Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange clobber of values in Math::Complex #9590

Closed
p5pRT opened this issue Dec 7, 2008 · 5 comments
Closed

strange clobber of values in Math::Complex #9590

p5pRT opened this issue Dec 7, 2008 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 7, 2008

Migrated from rt.perl.org#61142 (status was 'resolved')

Searchable as RT61142$

@p5pRT
Copy link
Author

p5pRT commented Dec 7, 2008

From david.madore@ens.fr

This is a bug report for perl from david.madore@​ens.fr,
generated with the help of perlbug 1.36 running under perl 5.10.0.


The following program​:

### cut after this line ###
#! /usr/local/bin/perl -w

use strict;
use warnings;
use Math​::Complex;

sub stupid {
  my $q = shift;
  my $qn = $q;
  while ( $qn >= 1.e-20 ) {
  $qn *= $q;
  }
}

my $z = Math​::Complex->make(0.5,0.5*sqrt(15));
$z = -1/$z; # Comment this for correct (but different) result!
my $q = exp(2*i*pi*$z);
stupid($q); # Comment this for correct result!
my $q2 = $q + 0.; # (Force printing in cartesian; this is unimportant)
print "z=$z\nq=$q2\n";
### cut before this line ###

gives the following output (with Debian's 5.10.0-17 both under i386
and amd64)​:

z=-0.125+0.484122918275927i
q=-5.19748331237927e-06+6.36508130212706e-22i

This is obviously wrong​: q is not exp(2*i*pi*z). The strangest thing
is​: if we remove the call to stupid($q) (which ought to do nothing at
all!) then the printed value for q is correct; and, as such, the
printed value for q is actually exp(2*i*pi*z0) where z0 is the
original value of z (before the $z=-1/$z line).

Am I out of my mind, or is this utterly broken?



Flags​:
  category=library
  severity=medium


Site configuration information for perl 5.10.0​:

Configured by Debian Project at Sun Nov 2 07​:30​:08 UTC 2008.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration​:
  Platform​:
  osname=linux, osvers=2.6.22-3-vserver-amd64, archname=x86_64-linux-gnu-thread-multi
  uname='linux excelsior 2.6.22-3-vserver-amd64 #1 smp tue feb 12 10​:01​:41 utc 2008 x86_64 gnulinux '
  config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.10.0 -Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2 -g',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
  ccversion='', gccversion='4.3.2', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
  libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
  perllibs=-ldl -lm -lpthread -lc -lcrypt
  libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0
  gnulibc_version='2.7'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl 5.10.0​:
  /etc/perl
  /usr/local/lib/perl/5.10.0
  /usr/local/share/perl/5.10.0
  /usr/lib/perl5
  /usr/share/perl5
  /usr/lib/perl/5.10
  /usr/share/perl/5.10
  /usr/local/lib/site_perl
  .


Environment for perl 5.10.0​:
  HOME=/home/david
  LANG=C
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/david/bin/vega.stars​:/home/david/bin/x86_64​:/home/david/bin​:/usr/local/bin​:/bin​:/usr/bin​:/usr/X11R6/bin​:/usr/local/games​:/usr/games
  PERL_BADLANG (unset)
  SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Mar 31, 2010

From @chorny

I have reported this bug to bug tracker of Math​::Complex, with seriously
simplified test case. See https://rt.cpan.org/Ticket/Display.html?id=56149

Problem is missing copy constructor.

On Sun Dec 07 15​:13​:24 2008, david.madore@​ens.fr wrote​:

This is a bug report for perl from david.madore@​ens.fr,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------

The following program​:

### cut after this line ###
#! /usr/local/bin/perl -w

use strict;
use warnings;
use Math​::Complex;

sub stupid {
my $q = shift;
my $qn = $q;
while ( $qn >= 1.e-20 ) {
$qn *= $q;
}
}

my $z = Math​::Complex->make(0.5,0.5*sqrt(15));
$z = -1/$z; # Comment this for correct (but different) result!
my $q = exp(2*i*pi*$z);
stupid($q); # Comment this for correct result!
my $q2 = $q + 0.; # (Force printing in cartesian; this is
unimportant)
print "z=$z\nq=$q2\n";
### cut before this line ###

gives the following output (with Debian's 5.10.0-17 both under i386
and amd64)​:

z=-0.125+0.484122918275927i
q=-5.19748331237927e-06+6.36508130212706e-22i

This is obviously wrong​: q is not exp(2*i*pi*z). The strangest thing
is​: if we remove the call to stupid($q) (which ought to do nothing at
all!) then the printed value for q is correct; and, as such, the
printed value for q is actually exp(2*i*pi*z0) where z0 is the
original value of z (before the $z=-1/$z line).

Am I out of my mind, or is this utterly broken?

-----------------------------------------------------------------

--
Alexandr Ciornii, http​://chorny.net

@p5pRT
Copy link
Author

p5pRT commented Mar 31, 2010

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 1, 2010

From @obra

Resolving per chorny

@p5pRT
Copy link
Author

p5pRT commented Apr 1, 2010

@obra - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant