On 19/06/2011 22:12, Patrick Dupre wrote:
On Sun, 19 Jun 2011, Uri Guttman wrote:
"PD" == Patrick Dupre <patrick.du...@york.ac.uk> writes:
PD> There is not option like (double) $res ?
rtfm to the rescue!
the synopsis shows how to do it. since it is a pragma it affects all
calculations in the scope. disabling the pragma is how you can get it
back to a regular float:
use bignum;
$x = 2 + 4.5,"\n"; # BigFloat 6.5
print 2 ** 512 * 0.1,"\n"; # really is what you think it is
print inf * inf,"\n"; # prints inf
print NaN * 3,"\n"; # prints NaN
{
no bignum;
print 2 ** 256,"\n"; # a normal Perl scalar now
}
This is what I tried first, the point is when you quite the
enclosure, even if you use no bignum, since the variables have declared
previous as bignumn any calculation using such variables previous
declared as bignum will be store in variables of the same type.
This make sense for perl, only a cast should allow changing the size.
In addition, the physical size (SV) of a bignum seems a lot bigger
than a usual NV.
BigFloat values are Perl Math::BigFloat obects, consisting of a blessed
anonymous hash with four fields, two of which have anonymous arrays as
values. That is why they take up so much more memory than standard
numeric values, and because the data structure only has meaning when
accessed by the object methods, there is no implicit conversion to the
standard format.
There is no casting in Perl - it simply converts between formats at run
time as required by the code.
As I have said before, I strongly recommend using Math::BigFloat instead
of bignum, as it makes it far easier to mix standard and BigFloat
values. All bignum does is to force all numeric values to be stored
implicitly as Math::BigFloat objects, and special care must be taken to
keep track of whether bignum is in effect or not at different places in
the code.
Cheers,
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/