Hi all.
I was communicating with a fellow on the IEEE-754 list. The discussion went a bit off topic so we communicated privately, and he encouraged me to discuss this with language developers.
This is mostly about handling errors in numerical computations. As we know, some computations have no meaningful results in studied maths, while we can define +1/+0 as +inf so that sane results may come back, stuff like 0/0 have no result that's acceptable in every situation. While sin(x)/x = 1 when x=0 may seem natural enough, it's not applicable to other places, not even the immediately obvious sin(x)/2x.
Rust pioneered in the field of safe programming, and introduced Option
and
Result
as container types for what may be results that may also be errors.
In my opinion, when NaN was introduced in IEEE-754-1985, NaN is exactly the
None
and Err
branch of Option
and Result
, and I think it's very
natural numerical results have similar properties, so that existing error
handling facilities can be naturally extended to scientific computing scenarios.
Truth to be told, I'm developing a little programming language of my own. In doing so, I consulted the IEEE-754 list on their take on status quo in numeric handling in existing languages. I asked and they expressed that the 2008 edition of the standard is meant to be a "prescriptive" "meta" standard for languages. They have achieved some success in the numerical aspect - mostly with reproducibility, but so far language developers haven't taken up much on error handling.
I don't intend to have a fierce competition with Rust in every aspect, and very likely my language can't, and in case my effort did prove to be a failure, I hope my idea can get carried on some way somewhere.
Here's an except from the specification of the language I'm developing:
-- BEGIN EXCERPT --
A bit of background first.
The IEEE-754 standard for floating point arithmetic specifies handling of exceptional conditions for computations. These conditions can be handled in the default way (default exception handling) or in some alternative ways (alternative exception handling).
The 1985 edition of the standard described exceptions and their default handling in section 7, and handling using traps in section 8. These were revised as "exceptions and default exception handling" in section 7 as well as "altenate exception handling attributes" in section 8 in the 2008 edition of the standard - these "attributes" are associated with "blocks" which (as most would expect) are group(s) of statements. Alternate exception handling are used in many advanced numerical programs to improve robustness.
As a prescriptive standard, it was intended to have language standards to describe constructs for handling floating point errors in a generic way that abstracts away the underlying detail of system and hardware implementations. In doing so, the standard itself becomes non-generic, and described features specific to some languages that were not present in others.
The CXING language employs null coalescing operators as general-purpose error-handling syntax, and make it cover NaNs by making them nullish. As an unsolicited half-improvement, I (dannyniu) propose the following alternative description for "alternate exception handling":
Language ought to specify ways for program to transfer the control of execution, or to evaluate certain expressions when a subset (some or all) of exceptions occur.
-- END EXCERPT --
Note IEEE-754-2008 devoted an entire chapter to what's known as the "alternate exception handling".
The draft spec for my language is posted at https://dannyniu.github.io/cxing-specs/cxing-spec-draft.pdf
The excerpt is on page 8.
Now ends the chit-chat. My questions for this thread are: would Rust be interested
in specifying floating point types as a first-class Number-Enum dual-identity
type that can be used for handling numerical errors in the match
expressions?
Or have Rust already introduced similar mechanism?
My intention is that, Rust can apply its error handling wisdom to IEEE numerics. A chapter in a prescriptive standard (I'm talking about Chap-8 in IEEE-754) cannot be proven right if nobody puts it into test.