Re: Exceptions vs NaN/NaI
On 2012-04-18 04:17:16 -0700, Dmitry Nadezhin wrote:
> It's a good point about trowing an exception.
>
> Some constructors and numeric functions are undefined at Level 1 for
> some argument values. Level 2 constructors/functions shall signal
> failure for such argument values.
>
> There are a few common ways to signal a failure in programming anguages:
> 1) Set a global/thread-local flag like "errno";
> 2) Return specifal value like NaI or NaN;
> 3) Throw a language exception (like in C++ or in Java).
>
> As far as I understand, the draft of the standard recommends(requires) (2).
> I don't like (1) too.
Actually, when (1) is done (for a real failure), this is in addition
to (2). In IEEE 754, (1) is useful if NaN disappears in a computation
(it is also useful to quickly check if something went wrong somwhere
in the computation, without having to test each final value).
In P1788, since it will not have (1), I wonder what would the result
of NaI U [0,1] be. If it is not NaI, at least some decoration should
be kept.
> However, shouldn't the P1788 be flexible enough to allow
> both level 2 operations that signal by (2)
> and level 2 operations that signal by (3) ?
I think that (2) should be mandatory, but (3) can be allowed if
the user requests it ((3) is not possible in all languages).
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)