1. Possible bug (sorry if it's a repeat)

It seems that Euphoria doesn't generate an error when an integer goes
out of bounds like so:

constant MAX_INTEGER = 1073741823
procedure display_integer(integer z)
    ? z
end procedure
integer x, y
x = MAX_INTEGER
x += 1 -- No error
x = MAX_INTEGER
x = x + 1-- No error
y = x -- No error
? integer(y) -- Displays 0
display_integer(y) -- Error here

I'm not sure whether this is a bug or it is supposed to happen, but it
seems like a bug considering:

constant MAX_INTEGER = 1073741823
type int(object x)
        return integer(x)
end type
int x
x = MAX_INTEGER
x += 1 -- This causes an error

Jeffrey Fielding
JJProg at cyberbury.net
http://members.tripod.com/~JJProg/

new topic     » topic index » view message » categorize

2. Re: Possible bug (sorry if it's a repeat)

JJProg at CYBERBURY.NET wrote:
>It seems that Euphoria doesn't generate an error when an integer goes
>out of bounds like so:
>
>constant MAX_INTEGER = 1073741823
>procedure display_integer(integer z)
>    ? z
>end procedure
>integer x, y
>x = MAX_INTEGER
>x += 1 -- No error
>x = MAX_INTEGER
>x = x + 1-- No error
>y = x -- No error
>? integer(y) -- Displays 0
>display_integer(y) -- Error here
>
>I'm not sure whether this is a bug or it is supposed to happen, but it
>seems like a bug considering:
>
>constant MAX_INTEGER = 1073741823
>type int(object x)
>        return integer(x)
>end type
>int x
>x = MAX_INTEGER
>x += 1 -- This causes an error

!!!

This does indeed seem to be an bug. And an intriguing one at that...

The docs detail an integer as a 31-bit signed number, making MAX_INTEGER
the maximum value an integer can have. Adding one to it (the first 'x += 1'
AND 'x = x + 1') should result in an error. And one would think that
passing an integer variable to the 'integer' typecheck function would
always return a 1. The 'display_integer' function bombed, like it should
have (based soley on y's value). Your second example also behaved
correctly.

Only Rob will be able to explain the 'why' of all this though (and be able
to fix it...)


Rod Jackson

new topic     » goto parent     » topic index » view message » categorize

3. Re: Possible bug (sorry if it's a repeat)

Jeffrey Fielding writes:
> constant MAX_INTEGER = 1073741823
> ...
> integer x, y
> x = MAX_INTEGER
> x += 1 -- No error
> x = MAX_INTEGER
> x = x + 1-- No error
> y = x -- No error

Yes, you've found a bug. Thanks.
It's trivial to fix. I'll do it for the next major release
(probably not the Linux pre-alpha - it's coming in a day or two.)

The code that adds the constant value 1 to an integer
(via += or the regular assignment)  tests for, but fails to
report, the type_check failure. If you add a different
number, or you subtract from the minimum integer,
it will be caught. Assigning y = x doesn't catch the error
because the compiler "knows" that x is an integer, so
no type check is performed.

Regards,
     Rob Craig
     Rapid Deployment Software
     http://members.aol.com/FilesEu/

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu