# Forum: Ruby Re: Work around for "Bignum out of Float range"?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
on 2006-02-02 20:35
```Dear Sam,

your problem is somewhat insolvable, since the square root of 5 has
an infinite number of digits, so it cannot be represented correctly
on any computer (in decimal or binary notation).
For arbitrary precision calculations with Fixnum exponents, there's
bigdecimal.

require "bigdecimal"

def calc(n,prec)
# prec is the precision of the sqrt  calculations
res=(BigDecimal.new("2") **  n)*BigDecimal("5").sqrt(prec)
end

puts calc(10000) => 0.44610[several lines of digits]*10^3011 (for
prec=10)

However, don't believe in too many of these digits...
If you still want to multiply by square roots accurately, it might be a
good
idea to look at continued fractions - every square root has a  continued
fraction representation that eventually ends in a periodic pattern.
There is an introduction to arithmetic with them at
_http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibon...
(http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibon...)

Hope that  helps,

Axel```
on 2006-02-03 00:25
```Nuralanur@aol.com wrote:
> def calc(n,prec)
> However, don't believe in too many of these digits...
> If you still want to multiply by square roots accurately, it might be a  good
> idea to look at continued fractions - every square root has a  continued
> fraction representation that eventually ends in a periodic pattern.
> There is an introduction to arithmetic with them at
> _http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibon...
> (http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibon...)
>
> Hope that  helps,
>
> Axel

Thank you, Axel.