Bignum doesn't work.....?

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 ) 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

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.0999
=> Infinity
irb(main):013:0> 4
999.0
=> Infinity
irb(main):014:0> 4**999
=>
28703267381856363105820830029442049600557942552217380011941068420644156534809
25784641648715791265674796114911597468656933617797402157638328564828390416632963
47824972863280700001721947870600112178572317475158715611954038659115970909868292
56510116588492726249139540599702236157401405827912384041055492583170336042227246
11462640059487120197851472523369412510725067917665645763050203305907032294031697
08293016497488491045317554449646010105399632958128852223584755229801387394458974
18009790020489304157645688845106395931503882087196604858013627228818945970656293
858882200205710692704491363440546212787257344


Marcel