Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Help me make a test case for Math::BigFloat

by BrowserUk (Patriarch)
on Mar 07, 2006 at 04:55 UTC ( #534832=note: print w/replies, xml ) Need Help??


in reply to Re^2: Help me make a test case for Math::BigFloat
in thread Help me make a test case for Math::BigFloat

Hmm. There seem to be two interacting problems here.

  1. exp doesn't appear to be overloaded by either bignum or Math::BigFloat?
    #!perl -slw use strict; use overload; #use bignum; use Math::BigFloat; printf "exp(-7e-17): %.17f\n", my $exp = exp( Math::BigFloat->new( '-7 +e-17' ) ); eval{ print overload::Overloaded( $exp ) } or warn $@; print overload::StrVal( $exp ); printf "1-exp(-7-e17): %.17f\n", Math::BigFloat->new("1") - $exp; __END__ C:\test>junk7 exp(-7e-17): 0.99999999999999989 Can't call method "can" without a package or object reference at c:/Pe +rl/lib/overload.pm line 54. 1 1-exp(-7-e17): 0.00000000000000000
  2. And with bignum enabled, Math::BigFloat seems to forget how to do math? At least if the math involves one BigMath object and one normal perl number.
    #!perl -slw use strict; use overload; use bignum; use Math::BigFloat; printf "exp(-7e-17): %.17f\n", my $exp = exp( Math::BigFloat->new( '-7 +e-17' ) ); eval{ print overload::Overloaded( $exp ) } or warn $@; print overload::StrVal( $exp ); printf "1-exp(-7-e17): %.17f\n", Math::BigFloat->new("1") - $exp; __END__ C:\test>junk7 exp(-7e-17): 0.99999999999999989 Can't call method "can" without a package or object reference at c:/Pe +rl/lib/overload.pm line 54. 1 1-exp(-7-e17): 1.00000000000000000

All of which makes me glad that I rarely need the accuracy beyond 53-bits and when I do, 64-bit ints suffice.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Help me make a test case for Math::BigFloat
by spiritway (Vicar) on Mar 07, 2006 at 06:45 UTC
    All of which makes me glad that I rarely need the accuracy beyond 53-bits and when I do, 64-bit ints suffice.

    This is why I prefer to keep things as rationals (or bigrats), rather than floats - it's possible to represent them accurately without encountering the inevitable rounding or truncating errors. True, all the irrational numbers will still truncate, but the rationals won't. I only use the decimal representation for display purposes, sometimes.

      Note that all the brokenness here can be gotten also by saying use bigrat; instead of use bignum; - there's something about those modules that causes weirdness with exp of certain close-to-zero quantities. (but not all - change the -7e-17 to a -7e-18 and all is right with the universe again.)
      --
      @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

        AFAIK, there's no exp function for bigrat or Math::BigRat. It's a deficiency I'd like to fix, but I've never been able to work out an algorithm for calculating exp for rationals. There are certain series, of course, but they are unacceptably slow for practical use.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://534832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2022-11-30 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?