Ok, I’m sure there is an easy way round this, but I can’t see it…
I want to do this…
syscall 88,-18751827,672274793,1126301404
Which is the kernel sys_reboot call to power-off.
However, ruby kindly converts the last number, 1126301404 (0x4321fedc in
hex which fits nicely in a long) to a Bignum, but syscall only accepts a
Fixnum
Nobody has a solution?? Surely I haven’t stumped you all
Andrew Walrond wrote:
···
Ok, I’m sure there is an easy way round this, but I can’t see it…
I want to do this…
syscall 88,-18751827,672274793,1126301404
Which is the kernel sys_reboot call to power-off.
However, ruby kindly converts the last number, 1126301404 (0x4321fedc in
hex which fits nicely in a long) to a Bignum, but syscall only accepts a
Fixnum
At Tue, 27 May 2003 23:46:32 +0900, Andrew Walrond wrote:
However, ruby kindly converts the last number, 1126301404 (0x4321fedc
in hex which fits nicely in a long) to a Bignum, but syscall only
accepts a Fixnum
In message “Help! I don’t want a bignum…” on 03/05/27, Andrew Walrond andrew@walrond.org writes:
syscall 88,-18751827,672274793,1126301404
Which is the kernel sys_reboot call to power-off.
However, ruby kindly converts the last number, 1126301404 (0x4321fedc in
hex which fits nicely in a long) to a Bignum, but syscall only accepts a
Fixnum
Any idea how to get around this???
It’s a bug. I will fix it soon. Ask me for a patch, if you’re in
hurry.
However, ruby kindly converts the last number, 1126301404 (0x4321fedc in
hex which fits nicely in a long) to a Bignum, but syscall only accepts a
Fixnum
A Fixnum 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.
Fixnum objects have immediate value. This means that when they are
assigned or passed as parameters, the actual object is passed,
rather than a reference to that object. Assignment does not alias
Fixnum objects. There is effectively only one Fixnum object
instance for any given integer value, so, for example, you cannot
add a singleton method to a Fixnum.
Nobody has a solution?? Surely I haven’t stumped you all
Write your own C extension that accepts Bignums.
Of course there should be a better solution.
Andrew Walrond wrote:
Ok, I’m sure there is an easy way round this, but I can’t see it…
I want to do this…
syscall 88,-18751827,672274793,1126301404
Which is the kernel sys_reboot call to power-off.
However, ruby kindly converts the last number, 1126301404 (0x4321fedc in
hex which fits nicely in a long) to a Bignum, but syscall only accepts a
Fixnum
Any idea how to get around this???
Andrew Walrond
Regards,
Michael
···
On Wed, May 28, 2003 at 07:14:04AM +0900, Andrew Walrond wrote:
Nobody has a solution?? Surely I haven’t stumped you all
No, we’re waiting for the first poster to shoot him down then. Ooops, that
might be me then…
My guess would be, that you might have found an error in ‘syscall’ and / or
Fixnum and / or conversion between number literals and objects.
Maybe someone more intimate with the ruby source (matz?) could comment on
this.
Regards
robert
···
Andrew Walrond wrote:
Ok, I’m sure there is an easy way round this, but I can’t see it…
I want to do this…
syscall 88,-18751827,672274793,1126301404
Which is the kernel sys_reboot call to power-off.
However, ruby kindly converts the last number, 1126301404 (0x4321fedc in
hex which fits nicely in a long) to a Bignum, but syscall only accepts a
Fixnum
It’s a bug. I will fix it soon. Ask me for a patch, if you’re in
hurry.
Thought so Although I don’t expect syscall gets used too often.
I need compatibility with current ruby versions, so I’m going with the
extension option, but it would be good to get it fixed. Nobu’s patch
looks good.
This is the correct behaviour. The valid range for a fixnum is -(230)
to (230)-1
For instance, if your machine had an 8bit word, then…
8bits considered as unsigned can hold 0 to 255 (0 to (28)-1)
8bits considered as signed can hold -128 to 127 (-(27) to (2**7)-1)
But ruby reserves one of those bits, so we only have 7 to play with,
giving a valid range of -(26) to (26)-1, where 6 is the number of
bits in our word minus 2
Now back to our realistic 32bit word; 6 becomes 32-2 = 30 and our valid
range is -(230) to (230)
Read up on twos complement if this makes no sense. Hope this helps
Write your own C extension that accepts Bignums.
Of course there should be a better solution.
Already done it And as this was the first time I’d done this I was
amazed to have a working extension inside 10 minutes! I am more
impressed with this language every day.