Floating point exceptions

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

Floating point exceptions

Reuben Thomas-3
First, please correct me if I'm wrong, but it seems from K&R second edn that
the behaviour of ANSI C '89 on floating point division by zero is undefined.
Am I correct?

The reason I ask is that I came across the problem in my EPOC port of Lua
that by default EPOC traps division by zero. I was able to turn it off, but
this meant I had to add an initialisation function, which is called (in my
port) by main() in lua.c, but in a cleaner implementation should be called
from within the Lua library (perhaps?).

I know that the C'99 standard gives access to the floating point state via
fenv.h, so perhaps this should be considered moot, but I was wondering if it
would be worth having some sort of standard hook (either in lua.c, or in
lua_open, but this is trickier) for system-specific initialisation of this
sort.

-- 
http://sc3d.org/rrt/ | wit, n.  educated insolence (Aristotle)


Reply | Threaded
Open this post in threaded view
|

Re: Floating point exceptions

Luiz Henrique de Figueiredo
>First, please correct me if I'm wrong, but it seems from K&R second edn that
>the behaviour of ANSI C '89 on floating point division by zero is undefined.
>Am I correct?

Yes.

>The reason I ask is that I came across the problem in my EPOC port of Lua
>that by default EPOC traps division by zero. I was able to turn it off, but
>this meant I had to add an initialisation function, which is called (in my
>port) by main() in lua.c, but in a cleaner implementation should be called
>from within the Lua library (perhaps?).

You might want to add a matherr handler in lmathlib.c.
Perhaps this should be part of the official distribution.
matherr is ANSI C, but does the EPOC suport that?
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Floating point exceptions

Reuben Thomas-3
> >The reason I ask is that I came across the problem in my EPOC port of Lua
> >that by default EPOC traps division by zero. I was able to turn it off, but
> >this meant I had to add an initialisation function, which is called (in my
> >port) by main() in lua.c, but in a cleaner implementation should be called
> >from within the Lua library (perhaps?).
>
> You might want to add a matherr handler in lmathlib.c.
> Perhaps this should be part of the official distribution.
> matherr is ANSI C, but does the EPOC suport that?

What is "matherr"? I can't find anything about this in the ISO standard
draft, system manpages or K&R.

-- 
http://sc3d.org/rrt/ | Caution Children At Play Drive Slowly


Reply | Threaded
Open this post in threaded view
|

Re: Floating point exceptions

Luiz Henrique de Figueiredo
In reply to this post by Luiz Henrique de Figueiredo
>What is "matherr"? I can't find anything about this in the ISO standard
>draft, system manpages or K&R.

I'm sorry. I learned about "matherr" back in my DOS days, and I assumed that
"matherr" was ANSI C, but it's not.  Harbison and Steele say that "matherr"
comes from System V Unix. Turbo C, Watcom C and Microsoft C all had "matherr".

Anyway, "matherr" does not handle division by zero and so all this is moot.
Sorry about the noise.
--lhf