Is this a bug?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Is this a bug?

Gavin Wraith-2
Is this a bug in lua or in my C compiler (Gnu C)?
Try
   x = tonumber("FFFFFFFF",16)
   print(x+1)
   write(format("%d\n",x+1))

For me it gives
   4294967296
   Uncaught trap: Floating point exception

In my view it ought to truncate gracefully and give
   4294967296
   0
 
 What does yours do? 
-- 
Gavin Wraith ([hidden email]) or ([hidden email])
Home page: http://www.wraith.u-net.com/


rje
Reply | Threaded
Open this post in threaded view
|

Re: Is this a bug?

rje
On Sun, Feb 04, 2001 at 11:06:00PM +0000, Gavin Wraith wrote:
> Is this a bug in lua or in my C compiler (Gnu C)?
> Try
>    x = tonumber("FFFFFFFF",16)
>    print(x+1)
>    write(format("%d\n",x+1))
> 
> For me it gives
>    4294967296
>    Uncaught trap: Floating point exception
> 
> In my view it ought to truncate gracefully and give
>    4294967296
>    0
>  
>  What does yours do? 

I'm wondering if it's a problem with RISC OS' FPE, because Lua
post-mortems when compiled with Norcroft/ARM CC, GCC or EasyC
when this is executed, but seems to function correctly when
compiled with GCC and run on a i386 Linux box.  If somebody wants
a nice stack backtrace from my RISC OS port, just ask.  It
might help...

-- 
Rob Kendrick - http://www.digital-scurf.org/
Today is what happened to yesterday.

Reply | Threaded
Open this post in threaded view
|

Re: Is this a bug?

Luiz Henrique de Figueiredo
In reply to this post by Gavin Wraith-2
>Is this a bug in lua or in my C compiler (Gnu C)?
>Try
>   x = tonumber("FFFFFFFF",16)
>   print(x+1)
>   write(format("%d\n",x+1))
> What does yours do? 

My Linux gives

4294967296
-2147483648

This seems correct, except that conversion from double to int does not work
well when the double value is too large (ie does not fit into an int).
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Is this a bug?

Reuben Thomas-3
In reply to this post by rje
> I'm wondering if it's a problem with RISC OS' FPE, because Lua

I'm not running RISC OS on my Acorn at the moment, but under Linux the
script you give also works fine (except that the format returns 2147483647
rather than -21....8). I think GCC under ARM Linux also uses (a variant of)
the FPE, no?

In fact, there's no problem with the behaviour under RISC OS: the C89
standard doesn't say that floating point exceptions should be disabled by
default (as I believe C99 does).

So you should disable them (if possible). I had to do this under EPOC to
make divisions by zero work (what happens with those under RISC OS?).

Under ARM Linux, print(1/0) gives "inf" as expected.

-- 
http://sc3d.org/rrt/ | Si hoc legere scis nimium eruditionis habes.


rje
Reply | Threaded
Open this post in threaded view
|

Re: Is this a bug?

rje
On Mon, Feb 05, 2001 at 12:50:22PM +0000, Reuben Thomas wrote:
> > I'm wondering if it's a problem with RISC OS' FPE, because Lua
> 
> I'm not running RISC OS on my Acorn at the moment, but under Linux the
> script you give also works fine (except that the format returns 2147483647
> rather than -21....8). I think GCC under ARM Linux also uses (a variant of)
> the FPE, no?

No, Linux/ARM uses Corel's NetWinder floating point emulator, where RISC OS
uses ARM's/David Seal's FPE emulator.

Cheers,
-- 
Rob Kendrick - http://www.digital-scurf.org/
Tonight you will pay the wages of sin; Don't forget to leave a tip.