On 3/5/20 1:27 AM, Greg Ewing wrote:
On 5/03/20 4:08 pm, Richard Damon wrote:
Sometimes I wonder if since Python supports dynamic typing of results, might not do better by removing the NaN value from Floats and Decimals, and make the operations that generate the NaN generate an object of a special NaN type.
I don't see what problem that would solve. All it would do is enable us to claim that the float type was totally ordered, without technically lying. Any operation on floats would still be able to return a NaNType value that would get mixed in with your other float operations, so it would make no practical difference.
What it would allow would be for the Float type to say it was Totally Ordered, and sort (and related functions) could check that the sequence passed to them consisted of just totally ordered items, and throw an exception if some item passed to it wasn't Totally Ordered. I suppose that since Python is not only Dynamically typed, also supports Duck Typing, the float type could declare itself to be Totally Ordered and the Nan just remove that characteristic from itself. (Since Float is built in, that might need some implementation magic to do that). -- Richard Damon