Return class as Integer

A

Atheeq Pasha

hello,

Can anyone tell me how to get a return class as Integer in ruby?

and to use Integer.new method with parameter as a number..
 
G

Gary Wright

hello,

Can anyone tell me how to get a return class as Integer in ruby?

and to use Integer.new method with parameter as a number.

Integer is an abstract class is Ruby. You want a Fixnum
(32 bit integers) or a Bignum (arbitrarily large integers).

Fixnum and Bignum are subclasses of Integer. Just use regular
decimal notation to 'generate' fixnums and bignums instances.
=> Bignum



Gary Wright
 
R

Rob Biedenharn

I don't think Fixnums are 32 bit.

irb(main):008:0> (1 << 30).class
=> Bignum
irb(main):009:0> (1 << 29).class
=> Fixnum
irb(main):010:0>

This is on Ubuntu Linux.


No, but they're close enough. There's a few bits used to identify some
immediate values in the MRI implementation. On a 64-bit platform, a
Fixnum will be used up to (1 << 62 - 1). The difference tends to
matter only when you're trying to do true 32-bit (or 64-bit) things
like cryptographic algorithms where bit shifts or bit rotations are
defined on an exact word size.

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
G

Gary Wright

=20
=20
No, but they're close enough. There's a few bits used to identify some =
immediate values in the MRI implementation. On a 64-bit platform, a =
Fixnum will be used up to (1 << 62 - 1). The difference tends to matter =
only when you're trying to do true 32-bit (or 64-bit) things like =
cryptographic algorithms where bit shifts or bit rotations are defined =
on an exact word size.

Yep. Thanks for expanding on my post. I just didn't feel like all those =
details were going to be helpful in the context of the original =
question.=20

Gary Wright=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top