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


#69 Create nan PDL

David Mertens
Matthew McGillis

The following code return a -nan PDL for both values. Expected the first to be nan and the second to be -nan.


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


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

    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:


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

    -nan -inf -1 -0 0 1 inf nan

    However the same code using 5.10.1

    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

    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)