Help! I don't want a bignum

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

Nobody has a solution?? Surely I haven’t stumped you all :wink:

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

Hi,

···

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

syscall should accept also Bignums.

Index: io.c

RCS file: /cvs/ruby/src/ruby/io.c,v
retrieving revision 1.209
diff -u -2 -p -r1.209 io.c
— io.c 21 May 2003 17:49:18 -0000 1.209
+++ io.c 27 May 2003 16:27:58 -0000
@@ -3450,4 +3450,7 @@ rb_f_syscall(argc, argv)
arg[i] = (unsigned long)NUM2LONG(*argv);
}

  • else if (!SPECIAL_CONST_P(*argv) && BUILTIN_TYPE(*argv) == T_BIGNUM) {
  •   arg[i] = rb_big2ulong(*argv);
    
  • }
    else {
    VALUE v = *argv;


Nobu Nakada

Hi,

···

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.

						matz.

“Andrew Walrond” andrew@walrond.org wrote in message

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???

I don’t know, because on my (32-bit?) Win XP Pro:

···

C:>ruby -ve “puts((2**31).class)”
ruby 1.6.8 (2002-12-24) [i586-mswin32]
Bignum

C:>ruby -e “puts((2**30).class)”
Bignum

C:>ruby -e “puts((2**30 - 1).class)”
Fixnum

C:>ruby -e “puts(2**30 - 1)”
1073741823

C:>ri Fixnum

 class: Fixnum  < Integer

 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.

 <=>, Arithmeticoperations, Bitoperations, [], abs, div, divmod,
 id2name, modulo, quo, size, to_f, to_s, to_sym, zero?

What gives ?
– shanko

Nobody has a solution?? Surely I haven’t stumped you all :wink:

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:


ruby -r complex -e ‘c,m,w,h=Complex(-0.75,0.136),50,150,100;puts “P6\n#{w} #{h}\n255”;(0…h).each{|j|(0…w).each{|i|
n,z=0,Complex(.9i/w,.9j/h);while n<=m&&(z-c).abs<=2;z=zz+c;n+=1 end;print [10+n15,0,rand99].pack("C")}}’|display

“Andrew Walrond” andrew@walrond.org schrieb im Newsbeitrag
news:3ED3D146.5030009@walrond.org

Nobody has a solution?? Surely I haven’t stumped you all :wink:

No, we’re waiting for the first poster to shoot him down then. Ooops, that
might be me then… :slight_smile:

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

Any idea how to get around this???

Andrew Walrond

Yukihiro Matsumoto wrote:

It’s a bug. I will fix it soon. Ask me for a patch, if you’re in
hurry.

Thought so :wink: 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.

Andrew Walrond

Shashank Date wrote:

I don’t know, because on my (32-bit?) Win XP Pro:

C:>ruby -ve “puts((2**31).class)”
ruby 1.6.8 (2002-12-24) [i586-mswin32]
Bignum

C:>ruby -e “puts((2**30).class)”
Bignum

C:>ruby -e “puts((2**30 - 1).class)”
Fixnum

C:>ruby -e “puts(2**30 - 1)”
1073741823

What gives ?
– shanko

This is the correct behaviour. The valid range for a fixnum is -(230)
to (2
30)-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 (-(2
7) 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 :wink:

Andrew Walrond

Michael Neumann wrote:

Write your own C extension that accepts Bignums.
Of course there should be a better solution.

Already done it :wink: 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.

“Andrew Walrond” andrew@walrond.org wrote in message

Read up on twos complement if this makes no sense. Hope this helps :wink:

This makes perfect sense … I was ignoring the negative range (doh!) and
hence was confused …

···

Andrew Walrond