The following code return a -nan PDL for both values. Expected the first to be nan and the second to be -nan.
#!/usr/bin/perl
use strict;
use warnings;
use PDL;
my $c = PDL->new("nan");
print "nan: ".ref($c)." ".$c."\n";
$c = PDL->new("-nan");
print "-nan: ".ref($c)." ".$c."\n";
Chris Marshall
2012-05-21
I'm not sure that -NaN and +NaN is significant but we should
definitely be self-consistent.
Chris Marshall
2012-05-21
Please update this ticket with the output from perldl -V
and any other relevant version information. Thanks
Chris Marshall
2012-05-22
In what context is this causing problems?
Matthew McGillis
2012-05-22
nan and -nan are two very different things and not being able to differentiate is significant. So if assigning something nan results in -nan your results will be wrong.
The context outlined is causing the problem I need to be able to create a PDL with values that include nan -nan inf numbers etc and they need to be kept consistent with what I assign.
One environment:
perldl -V
perlDL shell v1.354
PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file
'COPYING' in the PDL distribution. This is free software and you
are welcome to redistribute it under certain conditions, see
the same file for details.
Summary of my PDL configuration
VERSION: PDL v2.4.10 (supports bad values)
$%PDL::Config = {
'BADVAL_PER_PDL' => '0',
'WITH_PROJ' => '0',
'PDL_CONFIG_VERSION' => '0.005',
'POSIX_THREADS_INC' => undef,
'FFTW_TYPE' => 'double',
'PDL_BUILD_DIR' => '/home/OCHZIFF/risk_mmcgillis/src/perl/PDL-2.4.10',
'FFTW_LIBS' => undef,
'WITH_FFTW' => '0',
'GSL_LIBS' => undef,
'WITH_IO_BROWSER' => '0',
'PROJ_INC' => undef,
'WHERE_PLPLOT_INCLUDE' => undef,
'HTML_DOCS' => '1',
'SKIP_KNOWN_PROBLEMS' => '0',
'WHERE_PLPLOT_LIBS' => undef,
'WITH_3D' => '0',
'WITH_POSIX_THREADS' => '1',
'POGL_VERSION' => '0.65',
'FFTW_INC' => undef,
'HIDE_TRYLINK' => '1',
'HDF_INC' => undef,
'WITH_HDF' => '0',
'POGL_WINDOW_TYPE' => 'glut',
'WITH_GD' => '0',
'WITH_BADVAL' => '1',
'FITS_LEGACY' => '1',
'WITH_SLATEC' => '1',
'BADVAL_USENAN' => '0',
'WITH_DEVEL_REPL' => '1',
'TEMPDIR' => '/tmp',
'PROJ_LIBS' => undef,
'USE_POGL' => '0',
'PDL_BUILD_VERSION' => '2.4.10',
'GD_LIBS' => undef,
'GSL_INC' => undef,
'GD_INC' => undef,
'WITH_GSL' => '1',
'OPTIMIZE' => undef,
'PDLDOC_IGNORE_AUTOLOADER' => '0',
'HDF_LIBS' => undef,
'POSIX_THREADS_LIBS' => undef,
'MALLOCDBG' => {},
'WITH_MINUIT' => '1',
'WITH_PLPLOT' => '0',
'MINUIT_LIB' => undef
};
Summary of my perl5 (revision 5 version 10 subversion 1) configuration:
Platform:
osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux-thread-multi
uname='linux x86-003.build.bos.redhat.com 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
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='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.4.4 20100726 (Red Hat 4.4.4-13)', 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='gcc', ldflags =' -fstack-protector'
libpth=/usr/local/lib64 /lib64 /usr/lib64
libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.12'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
Another Environment:
perldl -V
perlDL shell v1.354
PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file
'COPYING' in the PDL distribution. This is free software and you
are welcome to redistribute it under certain conditions, see
the same file for details.
Summary of my PDL configuration
VERSION: PDL v2.4.11 (supports bad values)
$%PDL::Config = {
'BADVAL_PER_PDL' => '0',
'WITH_PROJ' => '0',
'PDL_CONFIG_VERSION' => '0.005',
'POSIX_THREADS_INC' => undef,
'FFTW_TYPE' => 'double',
'PDL_BUILD_DIR' => '/home/OCHZIFF/risk_mmcgillis/src/perl/PDL-2.4.11',
'FFTW_LIBS' => undef,
'WITH_FFTW' => '0',
'GSL_LIBS' => undef,
'WITH_IO_BROWSER' => '0',
'PROJ_INC' => undef,
'WHERE_PLPLOT_INCLUDE' => undef,
'HTML_DOCS' => '1',
'SKIP_KNOWN_PROBLEMS' => '0',
'WHERE_PLPLOT_LIBS' => undef,
'WITH_3D' => '0',
'WITH_POSIX_THREADS' => '1',
'POGL_VERSION' => '0.65',
'FFTW_INC' => undef,
'HIDE_TRYLINK' => '1',
'HDF_INC' => undef,
'WITH_HDF' => '0',
'POGL_WINDOW_TYPE' => 'glut',
'WITH_GD' => '0',
'WITH_BADVAL' => '1',
'FITS_LEGACY' => '1',
'WITH_SLATEC' => '1',
'BADVAL_USENAN' => '0',
'WITH_DEVEL_REPL' => '1',
'TEMPDIR' => '/tmp',
'PROJ_LIBS' => undef,
'USE_POGL' => '0',
'PDL_BUILD_VERSION' => '2.4.11',
'GD_LIBS' => undef,
'GSL_INC' => undef,
'GD_INC' => undef,
'WITH_GSL' => '1',
'OPTIMIZE' => undef,
'PDLDOC_IGNORE_AUTOLOADER' => '0',
'HDF_LIBS' => undef,
'POSIX_THREADS_LIBS' => undef,
'MALLOCDBG' => {},
'WITH_MINUIT' => '1',
'WITH_PLPLOT' => '0',
'MINUIT_LIB' => undef
};
Summary of my perl5 (revision 5 version 10 subversion 1) configuration:
Platform:
osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux-thread-multi
uname='linux x86-003.build.bos.redhat.com 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
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='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.4.4 20100726 (Red Hat 4.4.4-13)', 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='gcc', ldflags =' -fstack-protector'
libpth=/usr/local/lib64 /lib64 /usr/lib64
libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.12'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
Chris Marshall
2012-05-22
Both print out as PDL [nan] with no -nan. for me.
Chris Marshall
2012-05-22
The problem here appears to be how perl itself
handles NaN values and not PDL. Could you give
a specific example in plain perl where you use the
difference between a -nan and +nan values? E.g.,
where the actual content of the NaN is needed.
That will help to formulate a way forward. Of course,
patches are always welcome...
Chris Marshall
2012-05-22
Chris Marshall
2012-05-22
More specifically, the issue is how perl handles stringification of
NaN values.
Matthew McGillis
2012-05-22
Not sure if this is what your after but I have code in 2.4.9 that effectively does this:
#!/usr/bin/perl
use strict;
use warnings;
use PDL;
my $c = PDL->new("nan");
my $z = PDL->ones(1,1,1);
$z->set(0,0,0,$c);
print $z;
Which produces the following:
[
[
[nan]
]
]
However for me with 2.4.10 and 2.4.11 the above produces:
[
[
[0]
]
]
Chris Marshall
2012-05-22
It appears that there is a bug/feature in using set()
with a nan piddle, a work around is to use $nan->sclr
to convert the pdl value into a perl scalar. E.g.,
pdl> $z->set(0,0,0,$c)
pdl> p $z
[
[
[0]
]
]
pdl> $z->set(0,0,0,$c->sclr)
pdl> p $z
[
[
[nan]
]
]
Matthew McGillis
2012-06-16
I have done some digging on this and a piece of this is probably in libc however something is also going on in pdl. What I would hope is that assuming a consistent libc for each of the following pieces of code:
1) infnan.c
2) perl.pl
3) pdl.pl
then each should produce identical computed results. However for me even with a consistent libc I do not get consistent results between the three.
My results:
1) infnan.c
+ -nan -inf -1 -0 0 1 inf nan
-nan -nan -nan -nan -nan -nan -nan -nan nan
-inf -nan -inf -inf -inf -inf -inf -nan nan
-1 -nan -inf -2 -1 -1 0 inf nan
-0 -nan -inf -1 -0 0 1 inf nan
0 -nan -inf -1 0 0 1 inf nan
1 -nan -inf 0 1 1 2 inf nan
inf -nan -nan inf inf inf inf inf nan
nan -nan nan nan nan nan nan nan nan
- -nan -inf -1 -0 0 1 inf nan
-nan -nan -nan -nan -nan -nan -nan -nan -nan
-inf -nan -nan -inf -inf -inf -inf -inf nan
-1 -nan inf 0 -1 -1 -2 -inf nan
-0 -nan inf 1 0 -0 -1 -inf nan
0 -nan inf 1 0 0 -1 -inf nan
1 -nan inf 2 1 1 0 -inf nan
inf -nan inf inf inf inf inf -nan nan
nan nan nan nan nan nan nan nan nan
* -nan -inf -1 -0 0 1 inf nan
-nan -nan -nan -nan -nan -nan -nan -nan nan
-inf -nan inf inf -nan -nan -inf -inf nan
-1 -nan inf 1 0 -0 -1 -inf nan
-0 -nan -nan 0 0 -0 -0 -nan nan
0 -nan -nan -0 -0 0 0 -nan nan
1 -nan -inf -1 -0 0 1 inf nan
inf -nan -inf -inf -nan -nan inf inf nan
nan -nan nan nan nan nan nan nan nan
/ -nan -inf -1 -0 0 1 inf nan
-nan -nan -nan -nan -nan -nan -nan -nan -nan
-inf -nan -nan inf inf -inf -inf -nan nan
-1 -nan 0 1 inf -inf -1 -0 nan
-0 -nan 0 0 -nan -nan -0 -0 nan
0 -nan -0 -0 -nan -nan 0 0 nan
1 -nan -0 -1 -inf inf 1 0 nan
inf -nan -nan -inf -inf inf inf -nan nan
nan nan nan nan nan nan nan nan nan
2) perl.pl
+ nan -inf -1 0 0 1 inf nan
nan nan nan nan nan nan nan nan nan
-inf nan nan inf -inf -inf -inf nan nan
-1 nan 0 1 -inf -inf -1 0 nan
0 nan 0 0 nan nan 0 0 nan
0 nan 0 0 nan nan 0 0 nan
1 nan 0 -1 inf inf 1 0 nan
inf nan nan -inf inf inf inf nan nan
nan nan nan nan nan nan nan nan nan
- nan -inf -1 0 0 1 inf nan
nan nan nan nan nan nan nan nan nan
-inf nan nan inf -inf -inf -inf nan nan
-1 nan 0 1 -inf -inf -1 0 nan
0 nan 0 0 nan nan 0 0 nan
0 nan 0 0 nan nan 0 0 nan
1 nan 0 -1 inf inf 1 0 nan
inf nan nan -inf inf inf inf nan nan
nan nan nan nan nan nan nan nan nan
* nan -inf -1 0 0 1 inf nan
nan nan nan nan nan nan nan nan nan
-inf nan nan inf -inf -inf -inf nan nan
-1 nan 0 1 -inf -inf -1 0 nan
0 nan 0 0 nan nan 0 0 nan
0 nan 0 0 nan nan 0 0 nan
1 nan 0 -1 inf inf 1 0 nan
inf nan nan -inf inf inf inf nan nan
nan nan nan nan nan nan nan nan nan
/ nan -inf -1 0 0 1 inf nan
nan nan nan nan nan nan nan nan nan
-inf nan nan inf -inf -inf -inf nan nan
-1 nan 0 1 -inf -inf -1 0 nan
0 nan 0 0 nan nan 0 0 nan
0 nan 0 0 nan nan 0 0 nan
1 nan 0 -1 inf inf 1 0 nan
inf nan nan -inf inf inf inf nan nan
nan nan nan nan nan nan nan nan nan
3) pdl.pl
[-nan -inf -1 0 0 1 inf nan]
[
[-nan]
[-inf]
[ -1]
[ 0]
[ 0]
[ 1]
[ inf]
[ nan]
]
[
[-nan -nan -nan -nan -nan -nan -nan nan]
[-nan -inf -inf -inf -inf -inf -nan nan]
[-nan -inf -2 -1 -1 0 inf nan]
[-nan -inf -1 0 0 1 inf nan]
[-nan -inf -1 0 0 1 inf nan]
[-nan -inf 0 1 1 2 inf nan]
[-nan -nan inf inf inf inf inf nan]
[-nan nan nan nan nan nan nan nan]
]
[
[-nan -nan -nan -nan -nan -nan -nan nan]
[-nan -nan inf inf inf inf inf nan]
[-nan -inf 0 1 1 2 inf nan]
[-nan -inf -1 0 0 1 inf nan]
[-nan -inf -1 0 0 1 inf nan]
[-nan -inf -2 -1 -1 0 inf nan]
[-nan -inf -inf -inf -inf -inf -nan nan]
[-nan nan nan nan nan nan nan nan]
]
[
[-nan -nan -nan -nan -nan -nan -nan nan]
[-nan inf inf -nan -nan -inf -inf nan]
[-nan inf 1 -0 -0 -1 -inf nan]
[-nan -nan -0 0 0 0 -nan nan]
[-nan -nan -0 0 0 0 -nan nan]
[-nan -inf -1 0 0 1 inf nan]
[-nan -inf -inf -nan -nan inf inf nan]
[-nan nan nan nan nan nan nan nan]
]
[
[-nan -nan -nan -nan -nan -nan -nan nan]
[-nan -nan 0 -0 -0 -0 -nan nan]
[-nan inf 1 -0 -0 -1 -inf nan]
[-nan -inf -inf -nan -nan inf inf nan]
[-nan -inf -inf -nan -nan inf inf nan]
[-nan -inf -1 0 0 1 inf nan]
[-nan -nan -0 0 0 0 -nan nan]
[-nan nan nan nan nan nan nan nan]
]
Matthew McGillis
2012-06-16
C Code
Matthew McGillis
2012-06-16
Perl Code
Matthew McGillis
2012-06-16
PDL Code
Matthew McGillis
2012-07-03
I really think the 2.4.10 and above releases of PDL have introduced some bugs that need to be resolved related to this. But, since so far this has not prompted anyone to resolve and it appears now to be flagged as a feature rather than bug I have attached the following:
1) A regression test script "scalar.t" that can be used on future versions of PDL to validate that PDL maintains consistent behavior for scaler values. I think the set of tests I have in it are reasonable although it could be easily expanded to be more comprehensive.
2) A diff for the file Basic/Core/Core.pm.PL of the changes I made to 2.4.11 to get the above script to pass all tests.
With the above any chance I can get an idea if/when the above might get included into a future release of PDL?
Matthew McGillis
2012-07-03
File diff of changes to resolve this bug.
Matthew McGillis
2012-07-03
Regression tests to validate PDL scalar values remain consistent.
David Mertens
2012-07-03
David Mertens
2012-07-03
David Mertens
2012-07-03
This particular issue has been fixed in git with commit 000212d. I did not include the test suite that you provided as most of it was redundant with other tests. I found that I was able to ascertain the sign of the nan by stringifying the value and checking for a dash in the string, and was thereby able to side-step the need to use Inline::Pdlpp to check the sign.
With this patch, I consider this bug resolved. However, there is the related bug that Perl and PDL do not differentiate between -0 and +0. This was included in the original test suite that you provided, but was not added to the current test suite because I am not sure how to manufacture a negative zero from within Perl. I will be happy to include the test once we have a means for manufacturing such a value.
Thanks for your persistence so far!
Matthew McGillis
2012-07-03
For -0 vs +0 see my signbit Inline code if you want to test if any PDL value is negative or positive including 0.
Matthew McGillis
2012-07-03
I'm a little confused on the -0 issue because when I ran perl these tests where passing:
ok(pdl("-0")->string,"-0","-0 string");
ok(pdl(-0),-0,"-0 value");
Which seems to me like PDL is correctly tracking -0 even without the singbit inline code.
David Mertens
2012-07-03
That may work on your Perl, operating system, architecture, but it doesn't work on my Perl, operating system, architecture (5.14.2, Linue Mint 13, Intel 686). This test script demonstrates my issues and fails for tests 3, 7, and 8:
use strict;
use warnings;
use PDL;
use Inline 'Pdlpp';
use Test::More tests => 8;
is(pdl("0")->string,"0","0 string");
is(pdl(0),0,"0 value");
is(pdl("-0")->string,"-0","-0 string");
is(pdl(-0),-0,"-0 value");
is(pdl(0)->signbit, 0, "signbit for pdl(0) is zero");
is(pdl('0')->signbit, 0, "signbit for pdl('0') is zero");
isnt(pdl(-0)->signbit, 0, "signbit for pdl(-0) is not zero");
isnt(pdl("-0")->signbit, 0, "signbit for pdl('-0') is not zero");
__DATA__
__Pdlpp__
pp_def('signbit',
Pars => 'a(); [o]c();',
Code => '$c()=signbit($a());'
);
Matthew McGillis
2012-07-03
The fact that we are getting different results I would argue is a bug.
For reference: perl 5.10.1, os Red Hat Enterprise Linux Server 6.1, Intel 686
Something in PDL for this test:
is(pdl("-0")->string,"-0","-0 string");
Is managing to store an actual negative zero float in the data and printing it out.
For this test:
is(pdl(-0),-0,"-0 value");
it is just confusing because perl simply maps -0 to 0 before anything sees it so it evaluates to true but is not actually testing what is desired. Perl does not seem to support negative zero. Even the bignum module seems to indicate it does not support negative zero.
But then the question still goes back to how is PDL managing to do it in the above case and then given the way perl seems to be should it?
Given current standards for floats I would say perl is wrong in not supporting -0 properly but I could see arguments on both sides given that perl tries to hide the actual data type and all though a float may support -0 an integer does not so it does get rather vague depending on what your thinking/expecting.
Matthew McGillis
2012-07-03
I may be wrong on what is happening internally for this test:
ok(pdl(-0),-0,"-0 value");
Because in my environment all of these pass:
ok(pdl("-0")->string,"-0","-0 string");
ok(pdl("-0")->signbit!=0,1,"-0 is negative");
ok(pdl(-0),-0,"-0 value");
ok(pdl("-0")->signbit!=0,1,"-0 is negative");