32 points · by ryantsuji · 4mo ago · 18 comments
I wish there were a recent remake of it.
It is certainly orders of magnitude simpler than specifications for things like HTML, CSS, C++ or Vulkan.
The source of the problem is elsewhere. Unlike in the first 2 or 3 decades after the invention of automatic computers, nowadays there are much more than a half of the programmers who never encounter in their jobs the need to solve problems where complicated numeric computations are important and where the knowledge of mathematics branches like arithmetic and algebra is important.
Moreover, the programmers that happen to work on compilers or standard libraries for programming languages are even more likely to belong to the class of programmers who are not interested in computational applications.
This has led to the current situation, when almost all programming languages, especially the most popular of them, have bad defaults for the IEEE 754 options and they provide very awkward means to access all the facilities specified by the standard.
A decent programming language should have 2 distinct types for floating-point numbers, one for those that cannot be NaNs (to be used only in a program that enables and handles invalid operation exceptions) and one for floating-point numbers that may be NaNs (to be used in programs that disable the invalid operation exception, like most programming languages wrongly do by default).
Moreover, a decent programming language should have 14 relational operators, to enable the correct use of partially-ordered sets, e.g. also for user-defined data types, not only for floating-point numbers.
With a standard programming language, which has only 6 relational operators, if one insists on keeping disabled the invalid operation exception, then every floating-point comparison must be preceded by testing the operands for being a NaN, which is tedious.
Zero is not absence of a value. It has a value, it happens to be 0. Same for undefined/infinity. They exist.
Let the hardware engineers figure out an efficient way to deal with it. If it costs more, well if we add up all of the costs of bugs due to zero/null conversions, maybe it was worth it.
Equality comparison must be reflexive for things on which it is defined.
It is wrong to say that NaN is not equal to Nan (because a NaN is neither equal nor not equal with a NaN).
When the invalid operation exception is disabled, because the programmer is too lazy to write a SIGFPE handler or for whatever other mechanism is provided by the operating system to report hardware exceptions, then the set of floating-point numbers is extended with NaNs and the resulting extended set is no longer a totally-ordered set, but only a set on which a partial order is defined.
While floating-point number with NaNs are the best known because they are standardized, there are a lot of real sets that are best modeled as partially-ordered sets, so programming languages should have supported this and programmers should have been taught that partial order relations are something normal and natural, not something weird.
In any partially-ordered set there are elements like the NaNs, on which the relations of order and of equality may be undefined.
Thus NaN is neither equal nor not equal with NaN, but this relationship is undefined.
While for totally-ordered sets 6 relational operators are sufficient, for partially-ordered sets 14 relational operators are necessary.
When the 6 ALGOL relational operators (inherited by all later programming languages) are extended to 14, 6 new operators are provided by the negation of the 6 ALGOL operators, because in a partially-ordered set none of the 6 negations is equivalent with one of the 6 standard operators (like it happens in totally-ordered sets, where e.g. "not less" is the same as "greater or equal"). (In this statement, I considered among the 6 standard operators "less or greater", like in BASIC or SQL "<>", instead of "not equal", like in C "!=".)
The remaining 2 extra relational operators are "less or equal or greater", which could be written "<=>" or ">=<", which may be true only when no operand is a NaN, and its negation, which is equivalent with "one of the operands is a NaN".