
On Mon, Dec 30, 2019 at 9:01 AM Richard Damon <Richard@damon-family.org> wrote:
On 12/29/19 4:30 PM, Chris Angelico wrote:
On Mon, Dec 30, 2019 at 5:48 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Sat, Dec 28, 2019 at 09:20:49PM -0800, Brendan Barnwell wrote:
Especially since it fails quite a few commonsense tests for whether or not something is a number:
- Do NANs appear anywhere on the real number line or complex plane?
- Can we successfully measure (say) the length of a piece of string and get a result of NAN inches?
- Can we successfully count the number of (say) spoons on a table and get a result of NAN?
- Do NANs obey, even approximately, the usual properties of numbers?
Be careful: This kind of logic and intuition doesn't always hold true even for things that we actually DO call numbers.
The first and forth test are reasonable tests for a real number (expressed as a float).
There's nothing about "expressed as a float" in the first test; it basically just uses the definition of "real number line" and "complex plane" to define them. Actually performing the test is not exactly practical, but it's valid. I don't know what you mean by the fourth test being a test for a real number.
The second does limit itself to positive reals, but is otherwise a reasonable test of something being numberish.
Have you ever successfully measured the length of a piece of string as being precisely pi inches? Does that mean that pi is not a positive real number?
The third is more a test of the Natural Numbers (or the Non-Negative Whole Numbers), which would map to the 'unsigned' type in some language, or a part of the range of integers.
No, the "unsigned" type in most languages is a finite subset of unsigned integers. To be fair, a 64-bit unsigned number is going to include every number of spoons you'll ever see on any table, but that doesn't equate it to the naturals. Also, zero creates a lot of strange paradoxes. There are zero spoons on this table, AND there are zero forks AND zero knives. Furthermore, there are zero woolly mammoths, zero cans of Heinz Baked Beans, and zero chunks of red Kryptonite. How can you count the number of Infinite Improbability Drives sitting on the table, if you don't even know what an Infinite Improbability Drive looks like? Intuition simply can't answer all of these questions. You have to start mathematically or by performing operations on numbers ("if I have three spoons and I remove one, I have 3-1 == 2 two spoons"), at which point you are taking a completely different approach.
Since Practicality trumps Purity, we don't need (or really want) a mathematically pure definition, and since it is admitted that the floating point representation is just an approximation of the Real Numbers, a pure definition probably doesn't work anyway (Pure Mathematics doesn't deal with approximations well).
We have a mathematic definition of the ideal Real Numbers, using any of a number of ways to build it, and then we say that floats are an approximation to that system.
But since they are an approximation, the rules for reals do not hold. For instance, addition of two positive real numbers always results in another real number that is larger than each of the originals. Not so for floats. (Although the (infinite) sum of every power of two can be shown to be -1, so take of that what you will.)
The question remains, what in the Real Numbers do you propose that the NaN IEEE value approximate? It really doesn't, so isn't a 'number', but just a value, used to represent things that aren't numerical answers when a operation needs to generate SOME answer.
The equally valid question also remains: what in the real numbers does float("inf") represent? That equally isn't a number, it is a value. It is used to represent things that aren't numerical answers.
The alternative to having NaN values in the representation would be for the operations that currently generate it to fault out and either kill the program or at least generate an exception.
Also true of infinity. Are you going to object to that? Floats are NOT pure mathematical concepts of numbers. They are a disgustingly practical approximation to them, with many compromises and many unintuitive behaviours, but incredibly useful ones. ChrisA