Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the integer named Fixnum in ruby? [closed]

I was wondering why Ruby names it Fixnum; other languages name it Integer, Int, Number, etc. I saw that Fixnum < Integer and Bignum < Integer, and Integer < Numeric and Float < Numeric. I guess it's because of the size:

1.class => Fixnum
(10**100).class => Bignum

And from the doc:

Holds Integer values that can be represented in a native machine word (minus 1 bit). If any operation on a Fixnum exceeds this range, the value is automatically converted to a Bignum

Why the name Fixnum? I thought about fixed number, but it's not fixed, nor fixed size number.

like image 619
Dorian Avatar asked Feb 18 '26 10:02

Dorian


1 Answers

This isn't something Ruby came up with — the term "fixnum" comes from Lisp. Just like in Ruby, a fixnum in Lisp is a number that can be represented by a machine integer. Although I've never seen a primary source to prove I'm right, I've always assumed the "fix" part of the name referred to the fact that it can only represent a fixed range of numbers, in contrast with the limitless bignum (which gets its freedom from limits at the expense of worse performance).

like image 57
Chuck Avatar answered Feb 21 '26 06:02

Chuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!