in reply to Unexpected inf and NaN
from the docs:
CAVEATS Do not try to be clever to insert some operations in between switching + libraries: ... This will create objects with numbers stored in two different backend +libraries, and VERY BAD THINGS will happen when you use these togethe +r:
so maybe better use ->bfloor() instead of int !?! :)
¹) but curiosity killed my cat: ;-)
code
output#!/usr/bin/perl -w use strict; use Math::BigFloat ':constant'; use Data::Dump qw/pp/; print "150 / 0.75 == ", 150 / 0.75, "\n"; print "150.5->bfloor() == ", 150.5->bfloor() / 0.75, "\n"; print "150 / 3.75 == ", 150 / 3.75, "\n"; print "150.5->bfloor() / 3.75 == ", 150.5->bfloor() / 3.75, "\n"; my $float=3.1415926; pp $float; pp $float->bfloor(); pp int($float);
150 / 0.75 == 200 150.5->bfloor() == 200 150 / 3.75 == 40 150.5->bfloor() / 3.75 == 40 bless({ _e => [7], _es => "-", _m => [1415926, 3], sign => "+" }, "Mat +h::BigFloat") bless({ _e => [0], _es => "+", _m => [3], sign => "+" }, "Math::BigFlo +at") bless({ sign => "+", value => [3] }, "Math::BigInt")
Please note that int produces an object of type Math::BigInt which was never used !!!
Not sure if Math::BigFloat should better try to overwrite CORE::int() differently...
Cheers Rolf
( addicted to the Perl Programming Language)
¹) nope it's overwritten, see update and following discussion.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unexpected inf and NaN
by syphilis (Archbishop) on Jan 10, 2014 at 09:43 UTC | |
by LanX (Saint) on Jan 10, 2014 at 09:54 UTC | |
|
Re^2: Unexpected inf and NaN ( use bignum)
by Anonymous Monk on Jan 10, 2014 at 10:07 UTC |