Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Catching exceptions into strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xleroy@p...>
Subject: Re: [Caml-list] Catching exceptions into strings
> Thanks for the clear explanation of a topic that always puzzled me.
> Personally, I could live with SIGFPE just aborting the program.  I'm also
> curious: is it possible to catch floating point errors in ocaml's bytecode?
> Or is this, too, dependent on the ansi C/Posix standards?

ISO C9X (the next generation C standard, not yet implemented by everyone)
provides ways to test for pending floating-point exceptional conditions
(overflows, NaNs, etc).  It does not (AFAIK) standardize an API to
turn some/all of these conditions into signals.

So, once C9X becomes common enough, the bytecode interpreter could
conceptually check after each floating-point operation.  I doubt we'll
ever do this, however, given that the IEEE "no exception" model seems
to become universal, even if you don't like it :-)  (See below.)

> I tried this with java and was interested to find that integer
> division by zero is caught but floating point division by zero isn't.  

It is "caught" not as an exception, but by returning the appropriate
values defined for this very purpose in IEEE arithmetic:
     1.0 / 0.0 = +Inf   -1.0 / 0.0 = -Inf   0.0 / 0.0 = NaN
This might not seem natural to you, but it's the result of years of
arguing among numerical experts, and is the standard towards which
both hardware and programming languages converge.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners