iakobski has asked for the wisdom of the Perl Monks concerning the following question:
The documentation for Math::BigFloat says that zero is stored as 0E1 - presumably for the same reason as DBI returns 0E0. However, although the exponent() function does return 1, it still evaluates to false in a boolean context:
use Math::BigFloat; my $x = Math::BigFloat->bzero(); my $y = '0e+1'; print $/, "x is " , $x->bsstr(); print $/, "y is " , $y; print $/; print $/, "x + 0 is " , $x + 0; print $/, "y + 0 is " , $y + 0; print $/; print $/, "x is " , ( $x ) ? "true" : "false"; print $/, "y is " , ( $y ) ? "true" : "false"; print $/; print $/, "x eq 0e+1 is ", ( $x eq '0e+1' ) ? "true" : "false"; print $/, "y eq 0e+1 is ", ( $y eq '0e+1' ) ? "true" : "false"; print $/, "x eq y is ", ( $x eq $y ) ? "true" : "false"; C:\iakobski\perl>test1.pl x is 0e+1 y is 0e+1 x + 0 is 0 y + 0 is 0 x is false y is true x eq 0e+1 is false y eq 0e+1 is true x eq y is false
My questions: 1. Why? 2. Anyone know what this comment means in the docs:
"A zero is represented and returned as 0E1, not 0E0 (after Knuth)."
-- iakobski
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Math::BigFloat and zero
by JavaFan (Canon) on Sep 23, 2010 at 16:12 UTC | |
by iakobski (Pilgrim) on Sep 24, 2010 at 06:52 UTC | |
by JavaFan (Canon) on Sep 24, 2010 at 13:23 UTC | |
by Anonymous Monk on Sep 24, 2010 at 06:56 UTC | |
by iakobski (Pilgrim) on Sep 24, 2010 at 12:42 UTC | |
by JavaFan (Canon) on Sep 24, 2010 at 13:29 UTC |