0
BigInt, FixNum and Integer
Please explain: Difference between int, bigint and fixnum in Ruby; as simple and clear as possible.
1 Answer
+ 1
Fixnum and Bignums are classes underlying the Integer class, so weâll talk about them in a second.
The Integer class is just like it sounds, a datatype that describes integers, numbers that have no fractional part as in most other programming languages.
For the next two, we need to talk about computers. In all likelihood, you are using a 32-bit or 64-bit system. What that actually means is unimportant, but you need to know that it describes the size of numbers your computer can *easily* manipulate. In Ruby, an integer is automatically treated like a Fixnum when a number fits in this range. Simply, a Fixnum is ONE item that your computer can use in calculations. 64-bit systems can handle larger numbers like this than 32-bit systems.
When a number exceeds this range, Ruby will automatically convert it to a Bignum. These are broken up into smaller pieces that your computer can handle and then are put back together as strings (or similar) when displayed. Bignums are slower for this reason.