Hi Alan: Looking at the PDL code, 'acos' is defined for both 'float' PDLs and 'double' PDLs based on the C library 'acos' function. It seems like the single precision 'acos' is being called instead of the double precision one. The value you get from 'p acos(-1.)' is the single precision value:
perldl> p acos(float(-1)) 3.14159274101257 perldl> p acos(double(-1)) 3.14159265358979 Even odder: On my machine, I get this: perldl> p acos(-1) 3.14159265358979 perldl> p acos(-1.) 3.14159274101257 (!) It seems that if you put a decimal point in, the value is interpreted as a 'float', not a 'double'. PDL folks: Any idea why -1 is interpreted as 'double' and '-1.' is interpreted as 'float'?? Regards, Doug dh...@ucar.edu Software Engineer IV UCAR - COSMIC, Tel. (303) 497-2611 On Thu, 11 Dec 2008, Doug Hunt wrote: > Alan, Andrew: Thanks for finding/fixing these problems. > >> You were correct it was a problem with the Perl math library. The main >> trouble I had in finding this was figuring out how to print out individual >> elements of a pdl array. For future reference, this worked: >> >> for (my $i = 0; $i < int($windings)*int($steps)+1; $i++) { >> printf("%f,%f,%f,%f\n", $phi->slice($i)->slice('(0)'), >> $phiw->slice($i)->slice('(0)'), $xcoord->slice($i)->slice('(0)'), >> $ycoord->slice($i)->slice('(0)')); >> } > > You can also do this: > > wcols $phi; > > --That will print out all 20,000 elements of $phi in a single column. Or > this: > > print $phi->mslice([0,99]); > > That will print out the first 100 elements of $phi. > >> >> The result showed the errors gradually increased with phi which lead me to >> the scale error in the PI value used in dphi. >> >> Here is the crux of that scale error. >> perldl> p 4*atan2(1,1) >> 3.14159265358979 >> perldl> p acos(-1.) >> 3.14159274101257 >> >> The first is the correct value of PI to the printed precision, the second >> is wrong in the 7th place. In contrast, the C math library (and every >> other language binding we have) calculates PI to full precision >> without problems for acos(-1.) >> >> Doug, will you please do the honors and make the appropriate bug report? >> This is ugly, and I am amazed such a perl math library error is still with >> us after all these years. > > It turns out that 'acos' is not a *perl* function, but it is a *PDL* > function. So, I have more control over this--I'll look into it. Good > catch! > > --Doug > > ------------------------------------------------------------------------------ > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. > The future of the web can't happen without you. Join us at MIX09 to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ > _______________________________________________ > Plplot-devel mailing list > Plplot-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/plplot-devel > ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel