If I do parseFloat("1e-9999") I expect the result to be 0, and maybe there is a flag or additional return value saying it's approximate.
For C++ there's a nice boost::numeric::interval library that handles it.
https://www.boost.org/doc/libs/1_66_0/libs/numeric/interval/...
Since the C programs I'm writing won't be using floating point types, I got lucky - because they are an absolute pain to deal with with any degree of certainty.
It's being written for a new OS kernel.
Is that a 3rd interpretation? Has the whole argument gone so meta already that its mostly a definitions fight?
Edit: this makes me recall the "rounding flag" [1] and hitting an instance where the hardware was set to do something i hadn't expected. Meta-discussion about the nature of "accuracy" ensued then too.
[1] https://www.keil.com/support/man/docs/armlib/armlib_chr13589...
IEEE floats are guaranteed to _do_ that. They’re not distributed evenly across their range, so the absolute error of replacing a real by the closest float will vary across their range.
They also aren’t distributed evenly after taking logarithms, so the relative error of replacing a real by the closest float will also vary across their range.
(That is unavoidable for the reals if you want to represent zero or negative numbers)
In fact the integer value of the binary representation of a float approximates crudely the logarithm of the float. This was used in Quake's famous inverse square root approximation
Look for the word BigFloat in your choice of language. For an alternate spin, look for a "rational number" library in your choice of language.
To keep things interesting, I would demonstrate computer science concepts with clips from popular movies.
When discussing integer overflows, I would use this Ali G clip: https://youtu.be/eB5VXJXxnNU?t=53
I also used that famous Fantasia clip to demonstrate infinite loops.
One day I'd love to create a YouTubs series where I teach computer science entirely with popculture references. Don't have the video editing skills for it, so if anyone wants to collaborate on this let me know :)
Using that the range of an IEEE-754 float is from -NaN to NaN
For a set to have a range that set must have a total order defined. If we want to find the range of a datatype we need to have a total ordering of all the possible values of that datatype. Total ordering is very relevant to the question at hand.
In particular, the using IEEE order and building a range contaning NaNs is not semantically useful. Another detail is the distinction between -0.0 and 0.0; if you naively use the IEEE ordering to construct a type system you will have some problems with for example clopen ranges (-0.0, 0.0] and [-0.0, 0.0)
I don't see how there's a problem with a range containing NaN. It's no weirder than a range containing infinity.
That's alone makes it rather weird
I can understand the confusion many have with NaN, but the idea is that it's not a number, so it's not equal to anything in a number-like type.