Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#69 Create nan PDL

open-fixed
David Mertens
None
8
2012-07-03
2012-05-21
Matthew McGillis
No

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";

Discussion

<< < 1 2 (Page 2 of 2)
  • 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.

     
  • Out of curiosity can you test this on your system:

    isnt(pdl(-0.0)->signbit,0,"-0.0 is negative");

     
  • David Mertens
    David Mertens
    2012-07-03

    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

     
  • Chris Marshall
    Chris Marshall
    2012-07-04

    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).

     
<< < 1 2 (Page 2 of 2)