in reply to Re: Math::BigFloat to native double?
in thread Math::BigFloat to native double?
Okay, return as a string and then force perl to numerise it.
Trouble is, something gets lost in the transition:
use Math::BigFLoat;; $n = Math::BigFloat->new( '3.1415926535897932384626433832795' );; print $n;; 3.1415926535897932384626433832795 $d = 0+$n->bstr;; ##### as a double printf "%.17f\n", $d;; ##### display to full precision 3.14159265358979310 $n -= $d;; ##### substract from the bigfloat print $n;; ##### and display the (bigfloat) result 0.0000000000000032384626433832795
But:
3.1415926535897932384626433832795 - 3.1415926535897931000000000000000 0.0000000000000001384626433832795 which is quite different to the +value from above! 0.0000000000000032384626433832795
I expected some minor discrepancies, but not an order of magnitude difference.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Math::BigFloat to native double?
by syphilis (Archbishop) on Jul 13, 2015 at 01:48 UTC | |
by BrowserUk (Patriarch) on Jul 13, 2015 at 04:22 UTC | |
by syphilis (Archbishop) on Jul 13, 2015 at 06:47 UTC | |
by BrowserUk (Patriarch) on Jul 13, 2015 at 07:32 UTC | |
by syphilis (Archbishop) on Jul 13, 2015 at 08:12 UTC | |
| |
|
Re^3: Math::BigFloat to native double?
by Anonymous Monk on Jul 12, 2015 at 21:31 UTC | |
by BrowserUk (Patriarch) on Jul 12, 2015 at 21:59 UTC | |
|
Re^3: Math::BigFloat to native double?
by Laurent_R (Canon) on Jul 12, 2015 at 21:33 UTC | |
by BrowserUk (Patriarch) on Jul 12, 2015 at 21:57 UTC |