# Work around for "Bignum out of Float range"?

**URL:** <https://www.ruby-forum.com/t/work-around-for-bignum-out-of-float-range/100428>\
**Category:** Ruby\
**Created:** [February 2, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/work-around-for-bignum-out-of-float-range/100428 "2006-02-02T19:29:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [February 2, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/work-around-for-bignum-out-of-float-range/100428/1 "2006-02-02T19:29:15Z")

</div>

Hi!

First, some codes.

* * *

def calc(n)  
(2 \*\* n) \* (5 \*\* 0.5)  
end

## puts calc(10000) =\>warning: Bignum out of Float range

I understand what the problem is.  
If I want to get the result, how can I work around the barrier?

Thanks.  
Sam

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [February 2, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/work-around-for-bignum-out-of-float-range/100428/2 "2006-02-02T20:32:40Z")

</div>

On 2/2/06, Sam K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I want to get the result, how can I work around the barrier?

here’s some hacky code which returns a 2-element array  
the first number is the significant digits and the second number is  
the exponent:

def calc(n)  
exp=0  
val = (2 \*\* n)  
while val_3 \> 1e290.to\_i  
val/=10  
exp+=1  
end  
val =(5\*\*0.5)  
unless val.to\_s.grep(/(.)e+(._)/).empty?  
val = $1.to\_f  
exp+=$2.to\_i  
end  
[val, exp]  
end

p calc 1  
p calc 10  
p calc 100  
p calc 1000  
p calc 10000

[4.47213595499958, 0]  
[2289.73360895978, 0]  
[2.83455291382873, 30]  
[2.39596608414461, 301]  
[4.46109674874798, 3010]

-Adam
