Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Exceptions vs NaN/NaI



I am sympathetic to enabling (3) as an option; Baker may be right this can
be accomplished by simply choosing our words carefully (thereby allowing the
possibility while at the same time not getting into domain of language
standards).

I believe the overall concept aligns fairly well with the decoration sytem
of compressed intervals that has been discussed in this forum before.

For example, the interval expression 1 / [0,1] may have one of two possible
outcomes depending on a user-specified preference. The first outcome may be
the bare interval
   1 / [0,1] = [1,+Inf]
if the user has specified that out of domain arguments are to be silently
ignored; the second outcome may be the bare decoration (NaI)
   1 / [0,1] = somewhereDefined
if the user has specified that out of domain arguments are an error. In the
second case, the bare decoration "somwhereDefined" will propagate through
the rest of a lengthy computation as NaI so it can be checked by the user.
Alternatively, an implementation may choose to throw the "somewhereDefined"
decoration as a C++ or Java exception (it would be nice if the standard
wording may allow this).

Nate


----- Original Message ----- From: "Dmitry Nadezhin" <dmitry.nadezhin@xxxxxxxxxx>
To: "Stds-1788" <stds-1788@xxxxxxxxxxxxxxxxx>
Sent: Friday, April 20, 2012 10:15 AM
Subject: >>: Exceptions vs NaN/NaI


----- Пересланное сообщение -----
От: dmitry.nadezhin@xxxxxxxxxx
Кому: rbk@xxxxxxxxxxxxx
Отправленные: Пятница, 20 Апрель 2012 г 18:41:09 GMT +04:00 Абу-Даби,
Маскат
Тема: Re: Exceptions vs NaN/NaI

Suppose that somebody writes an implementation of intervals in
his favorite language. Signatures of operations in language
may differ a little from abstract signatures of corresponding
P1788 operation. It is not 100% clear to me how to make conclusion
if language implementation conforms to the P1788 standard.

Of course, I concerned mostly about my interval library in Java.
I think about how much chages will be necessary to make it conformant.
The library implements infsup_F datatype, where F=ExtendedRational .
ExtendedRational consists of -oo, +oo, and of fractions p/q with
restrictions q != 0, abs(p) < N, abs(q) < N for some huge N. This type
dosn't contain
special value NaN. Numeric functions in my library throw Java
ArithmeticException when
arguments are out of domain. They never return NaN.

Now ExtendedRational is total-ordered type (it implements Java interface
Comparable).
I don't like an idea to add NaN to ExtendedRational, because it will loose
total order.
And now I try to understand if I will be forced to add NaN.

Shortly speeking, NaN is not necessary for implementations that throw
language exceptions instead of return NaN.

 -Dima

----- Исходное сообщение -----
От: rbk@xxxxxxxxxxxxx
Кому: dmitry.nadezhin@xxxxxxxxxx
Копия: eliasen@xxxxxxxxxxxxxx, stds-1788@xxxxxxxxxxxxxxxxx
Отправленные: Пятница, 20 Апрель 2012 г 17:20:41 GMT +04:00 Абу-Даби,
Маскат
Тема: Re: Exceptions vs NaN/NaI

Dima,

How do you envision enabling (3) through defining data types
and operations (my perceived scope of P-1788)?  Note that,
if our standards document is silent on this point, that
does not preclude languages from throwing such an
exception (in a non-standard way, or in a standard-way,
if specified in the language).

Baker

On 04/18/2012 06:17 AM, 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.
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) ?

   -Dima



--

---------------------------------------------------------------
Ralph Baker Kearfott,   rbk@xxxxxxxxxxxxx   (337) 482-5346 (fax)
(337) 482-5270 (work)                     (337) 993-1827 (home)
URL: http://interval.louisiana.edu/kearfott.html
Department of Mathematics, University of Louisiana at Lafayette
(Room 217 Maxim D. Doucet Hall, 1403 Johnston Street)
Box 4-1010, Lafayette, LA 70504-1010, USA
---------------------------------------------------------------