This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Other Languages and the fly likes Numbers & Range Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Numbers & Range" Watch "Numbers & Range" New topic

Numbers & Range

Sree Va
Ranch Hand

Joined: Jan 28, 2007
Posts: 38
Oh! Finally, a place to hold the count of all stars in the universe.


Ruby supports integers and floating point numbers. Integers can be any length (up to a maximum determined by the amount of free memory on your system). Integers within a certain range (normally -230 to 230-1 or -262 to 262-1) are held internally in binary form, and are objects of class Fixnum. Integers outside this range are stored in objects of class Bignum (currently implemented as a variable-length set of short integers). This process is transparent, and Ruby automatically manages the conversion back and forth.

num = 8
7.times do
print num.type, " ", num, "\n"
num *= num


Fixnum 8
Fixnum 64
Fixnum 4096
Fixnum 16777216
Bignum 281474976710656
Bignum 79228162514264337593543950336
Bignum 6277101735386680763835789423207666416102355444464034512896

We believe that every being is divine, is God. Every soul is a sun covered over with clouds of ignorance; the difference between soul and soul is owing to the difference in density of these layers of clouds. - Swami Vivekananda
Stuart Halloway

Joined: Jan 04, 2007
Posts: 2
Ruby is the first language I have used heavily where I don't even bother to remember what values fit in a Fixnum. The language deals elegantly enough with values that I can use my brain space for something else.
I agree. Here's the link:
subject: Numbers & Range
It's not a secret anymore!