Bugs: Browse | Submit New | Admin

[#7500] ^ | & Float bug

Date:
2006-12-30 16:08
Priority:
3
Submitted By:
Darren Smith (flagitious)
Assigned To:
Yukihiro Matsumoto (matz)
Category:
Language / Runtime / Core Libraries
State:
Open
Platform:
 
Summary:
^ | & Float bug

Detailed description
Operations such as 5^4.5, and 0|9.9 first convert the Float to an Integer to preform the calculation. However this is
a bug because it should be converting to a Fixnum because of cases such as this:

0|1e20
RangeError: float 1e+20 out of range of integer

1e20 is certainly out of range of integer, but why should it matter? It is certainly unexpected behavior.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-06-14 16:32
Sender: Shyouhei Urabe

OK I know what you are claiming.
I'd prefer prohibiting Floats from bitwise operations.
How about you matz?
Date: 2007-06-12 14:41
Sender: Darren Smith

I would expect it to equal 0|(1e20).to_i which is
100000000000000000000.

All of the bitwise functions have something like this:

if (TYPE(y) == T_BIGNUM) {
    return rb_big_and(y, x);
}
val = FIX2LONG(x) & NUM2LONG(y);

A potential fix would be to convert y to integer type before
checking if it is a bignum, or to check the size of a float
and call rb_big_and in a special case. Another solution
would be to disallow all automatic conversion from float to
integer in bitwise operations.

The reason I think this is a problem is because the user is
not supposed to care if a number is a Fixnum or a Bignum, it
is supposed to be transparent. But in these cases there is
different behavior (an error) occuring depending on the size
of values, even though it is possible to proceed but as
Bignum instead.
Date: 2007-06-12 06:01
Sender: Shyouhei Urabe

OK tell us exactly what you expect in the value of 0|1e20.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
assigned_toshyouhei2007-06-14 16:32shyouhei
summary^ | & Float bug2007-06-12 14:41flagitious
assigned_tonone2007-06-12 02:24zenspider
summary^ | & Float bug2007-06-12 02:24zenspider
category_idMisc / Other Standard Library2007-05-29 17:49zenspider
summary^ | & Float bug2007-05-29 17:49zenspider