Hi
I tried
(“aaa”*300000000000000000000000000000000000000000000000000000000000000000000000000000000000000).bytesize
But this gives me error
RangeError: bignum too big to convert into `long’
Why this? Mine is Ruby1.8.7
Thanks
Hi
I tried
(“aaa”*300000000000000000000000000000000000000000000000000000000000000000000000000000000000000).bytesize
But this gives me error
RangeError: bignum too big to convert into `long’
Why this? Mine is Ruby1.8.7
Thanks
It looks like for string multiplication, ruby can’t use Bignums.
Bignums are represented internally as strings of digits, and when doing
Bignum * Bignum ruby has to do the math one string digit by one string
digit at a time. Apparently, with String * Bignum ruby doesn’t know
what to do with ‘aaa’ * ‘3’, so ruby tries to convert ‘3’ to an actual
number.
Tom M. wrote in post #1007073:
Hi
I tried
(“aaa”*300000000000000000000000000000000000000000000000000000000000000000000000000000000000000).bytesize
But this gives me error
RangeError: bignum too big to convert into `long’
Do you really have that much memory on your machine? Because you just
asked Ruby to build a string that size (filling it with 'a’s), and then
count the bytes in it.
A ‘long’ is defined by the C standard to be at least 232 (+/- 2GB if
signed), but is 264 on many machines. That’s a lot of memory
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs