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";
Sorry about that last message that test is also not what I wanted. This is what I was trying to do:
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");
the 4th test above fails.
Which is what I was expecting if my assumption about what perl is doing to -0 was correct.
Found this interesting which is related to your version of perl:
http://search.cpan.org/~jesse/perl-5.14.0/pod/perldelta.pod#Negative_zero
Also found the module it references interesting:
http://search.cpan.org/~zefram/Data-Float-0.012/lib/Data/Float.pm
Out of curiosity can you test this on your system:
isnt(pdl(-0.0)->signbit,0,"-0.0 is negative");
On my machine, this code:
isnt(pdl(-0.0,->signbit, 0, "-0.0 is nagative");
fails. :-(
I downloaded 5.16.0 of perl and installed on my box. This code:
#!/usr/bin/perl
my @items=(-nan, -inf, -1.0, -0.0, 0.0, 1.0, inf, nan);
for ($i=0;$i<=$#items;$i++) {
print(sprintf("%4g ",$items[$i]));
}
print "\n";
Produces:
-nan -inf -1 -0 0 1 inf nan
However the same code using 5.10.1
Produces:
nan -inf -1 -0 0 1 inf nan
Lots of strangeness going on out of curiosity what version of glibc do you have? my system is using 2.12
Thanks for running this problem to ground.
I tried the latest PDL git and all tests passed
except for the -nan is -nan one (on cygwin
perl 5.10.1 the minus sign does not appear
to propagate).