# Biggest number

**URL:** <https://www.ruby-forum.com/t/biggest-number/166451>\
**Category:** Ruby\
**Created:** [April 25, 2009, 12:34pm UTC](https://www.ruby-forum.com/t/biggest-number/166451 "2009-04-25T12:34:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaesgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@jaesgar](https://www.ruby-forum.com/u/jaesgar)\
**Post date:** [April 25, 2009, 12:34pm UTC](https://www.ruby-forum.com/t/biggest-number/166451/1 "2009-04-25T12:34:21Z")

</div>

I’m learning ruby, and I want to know if it is any way to know the  
biggest number to be represented with a specific type of number (Fixnum,  
Bignum, Float).

Thank you.

---

<div class="post-metadata">

**Author:** ![jaesgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@jaesgar](https://www.ruby-forum.com/u/jaesgar)\
**Post date:** [April 25, 2009, 1:09pm UTC](https://www.ruby-forum.com/t/biggest-number/166451/2 "2009-04-25T13:09:35Z")

</div>

Javier E. wrote:

> I’m learning ruby, and I want to know if it is any way to know the  
> biggest number to be represented with a specific type of number (Fixnum,  
> Bignum, Float).

Float is a standard 64-bit IEEE floating point value. There are several  
constants on the Float class that can tell you whatever you need:

âž” jruby -e “p Float::constants”  
[“MAX”, “MAX\_10\_EXP”, “MANT\_DIG”, “RADIX”, “DIG”, “MIN”, “ROUNDS”,  
“MIN\_EXP”, “EPSILON”, “MIN\_10\_EXP”, “MAX\_EXP”]

Fixnum has no such constants, but on most implementations (CRuby, JRuby,  
Rubinius at least) its max size is dependent on how large its basis  
representation is. I believe it can be either “32” or “64” bits on  
CRuby, where on JRuby it is always “64” bits:

âž” ruby -e “p (1 \<\< (1.size \* 8 - 1)) - 1”  
2147483647

âž” ruby -e “p -(1 \<\< (1.size \* 8 - 1))”  
-2147483648

âž” jruby -e “p (1 \<\< (1.size \* 8 - 1)) - 1”  
9223372036854775807

âž” jruby -e “p -(1 \<\< (1.size \* 8 - 1))”  
-9223372036854775808

The loss of one bit of precision on most impls is to emulate CRuby’s  
implementation of Fixnum as a tagged pointer, where the top bit  
indicates whether an object pointer is a real pointer or a Fixnum  
value).

And Bignum has no min or max size, other than the maximum size of a  
byte[] on your system.

- Charlie

---

<div class="post-metadata">

**Author:** ![jaesgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@jaesgar](https://www.ruby-forum.com/u/jaesgar)\
**Post date:** [April 25, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/biggest-number/166451/3 "2009-04-25T14:10:53Z")

</div>

Thank you Charlie

Charles Oliver N. wrote:

---

<div class="post-metadata">

**Author:** ![jaesgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@jaesgar](https://www.ruby-forum.com/u/jaesgar)\
**Post date:** [April 25, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/biggest-number/166451/4 "2009-04-25T20:21:29Z")

</div>

Javier E. wrote:

> I’m learning ruby, and I want to know if it is any way to know the  
> biggest number to be represented with a specific type of number (Fixnum,  
> Bignum, Float).
> 
> Thank you.

irb(main):005:0\> (2**30).class  
=\> Bignum  
irb(main):006:0\> (2**30-1).class  
=\> Fixnum

irb(main):009:0\> RUBY\_VERSION  
=\> “1.8.6”
