Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Approximating Square Roots

by suaveant (Parson)
on Oct 05, 2001 at 21:26 UTC ( [id://117050]=note: print w/replies, xml ) Need Help??


in reply to Approximating Square Roots

I believe your problem is that though you are creating a bigfloat number, you are doing simple math operations in perl. You should probably be using Math::BigFloat's fdiv and the like for your math.
I will point out that your code works for normal perl sized numbers...

                - Ant
                - Some of my best work - Fish Dinner

Replies are listed 'Best First'.
Re: Re: Approximating Square Roots
by sifukurt (Hermit) on Oct 05, 2001 at 21:36 UTC
    There was an intermediate step where I was using bdiv() and badd() and the like. The results were the same. And with Math::BigFloat, once you've created a new() item, it isn't expressly necessary to use bdiv(), bpow(), etc. You can use standard math operators, which is what I chose to do in this most recent version simply for readability. It was easier (to me, at least) to follow the logic.
    ___________________
    Kurt
      Sorry for the late answer, found your question by chance via Google.
      You probably stumbled over one of the many bugs in the old BigFloat package. There is a newer, much improved version on CPAN, and you should give it a try. It also has a bsqrt() function, that actually works ;)
      use Math::BigFloat v1.22; $x = Math::BigFloat->new('1234.567'); print "square root of $x is ",$x->bsqrt(),"\n";
      HTH Tels

      If you have more questions, feel free to contact me at tels at bloodgate dot com. Thanxy!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-28 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found