Ruby LanguageNumbers


Remarks

Numbers hierarchy

Ruby includes several built-in classes to represent numbers:

Numeric
  Integer
    Fixnum    # 1
    Bignum    # 10000000000000000000
  Float       # 1.0
  Complex     # (1+0i)
  Rational    # Rational(2, 3) == 2/3
  BigDecimal  # not loaded by default

The most common are:

  • Fixnum to represent, for instance positive and negative integers
  • Float to represent floating point numbers

BigDecimal is the only one not loaded by default. You can load it with:

require "bigdecimal"

Note that in ruby 2.4+, Fixnum and Bignum are unified; all integers are now just members of the Integer class. For backwards compatibility, Fixnum == Bignum == Integer.