# Bignum doesn't work.....?

**URL:** <https://www.ruby-forum.com/t/bignum-doesnt-work/76208>\
**Category:** Ruby\
**Created:** [November 16, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/bignum-doesnt-work/76208 "2006-11-16T18:40:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@Ethan\_P](https://www.ruby-forum.com/u/Ethan_P)\
**Post date:** [November 16, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/bignum-doesnt-work/76208/1 "2006-11-16T18:40:51Z")

</div>

Forgive me if this has been answered, I have look all around and can’t  
seem  
to find an answer. I am trying to implement the Fermat primality test (  
[Fermat primality test - Wikipedia](http://en.wikipedia.org/wiki/Fermat_primality_test) ) in Ruby. The  
problem is  
everytime ruby does the a^(n-1) computation, it seems to stumble on  
numbers  
like 1000 (so its doing a^999). I have set both a and n to fixnums, and  
according to everything I have read, it should switch to bignum if the  
result is too big. But it doesn’t seem to do that, it just seems to spit  
out  
infinity. Any ideas? I used the latest one click installer to install  
Ruby.

Ethan

---

<div class="post-metadata">

**Author:** ![Ethan\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@Ethan\_P](https://www.ruby-forum.com/u/Ethan_P)\
**Post date:** [November 16, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/bignum-doesnt-work/76208/2 "2006-11-16T20:45:20Z")

</div>

It sounds like either the base or the exponent you are using (or both)  
are floats.

The following demonstrates this fairly well:

irb(main):012:0\> 4.0**999  
=\> Infinity  
irb(main):013:0\> 4**999.0  
=\> Infinity  
irb(main):014:0\> 4\*\*999  
=\>  
28703267381856363105820830029442049600557942552217380011941068420644156534809  
25784641648715791265674796114911597468656933617797402157638328564828390416632963  
47824972863280700001721947870600112178572317475158715611954038659115970909868292  
56510116588492726249139540599702236157401405827912384041055492583170336042227246  
11462640059487120197851472523369412510725067917665645763050203305907032294031697  
08293016497488491045317554449646010105399632958128852223584755229801387394458974  
18009790020489304157645688845106395931503882087196604858013627228818945970656293  
858882200205710692704491363440546212787257344

–  
Marcel
