Why is an integer called Fixnum in ruby?

I was wondering why Ruby calls it Fixnum; other languages ​​call it Integer, Int, Number, etc. I saw that Fixnum < Integerand Bignum < Integer, and Integer < Numeric, and Float < Numeric. I guess this is due to size:

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

And from the document :

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

Why a name Fixnum? I was thinking about a fixed number, but this is not fixed, as well as a fixed size.

+3
source share
3 answers

, Ruby - "fixnum" Lisp. Ruby, fixnum Lisp - , . , , , , "" , , bignum ( ).

+7

2 :

, ( 1 ):  Fixnums. ( object_id .  ? , , , .   1 ).

, : Bignums ( object_id   -Fixnums.)

p 1.is_a?(Integer) #=> true
p (10**100).is_a?(Integer) #=> true
+2

In Ruby, this is an object that has immediate meaning. Which basically means that the object is passed, not the value. Therefore, to be honest, this is just the name of the object, not the type.

More details here: http://www.ruby-doc.org/core-2.1.0/Fixnum.html

0
source

All Articles