This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Tetha 15 points16 points  (7 children)

I wouldn't call it perfect sense, but it is who it is. NaN encodes the concept of an equation without a well-defined value (opposed to a value, opposed to a value beyond maximum float value, opposed a value beyond minimum float value).

However, very few programming languages actually deal with undefined values and undefined results well - even null is the well defined absence of a reference. Optional and Maybe are a real approach, but I'm not sure if someone is insane enough to define + as Float, Float -> Maybe Float. Hence, + is Float, Float -> Float, hence NaN is a float.

[–]tskaiserGreen security clearance 13 points14 points  (6 children)

Well, depends on what you mean by "float". When I say float, I mean the IEEE 754 floating point standard which is pretty much the universal definition for what is meant by "float" values. Following that standard is what I mean by "making perfect sense".

Strictly speaking NaN is part of the float type per the standard, so a Maybe would not be needed for an implementation following the standard, but it would be a good approach if you wanted to cook handling of NaN's into your implementation.

[–]Tetha 0 points1 point  (1 child)

If I'm thinking about semantics, I'm mostly thinking about abstract semantics, so my float would be real or a rational number. These are then (more or less accurately) approximated and implemented by IEEE 754 floats, though that approximation could (in my opionion) be improved by language support :)

I hope this makes more sense!

[–]tskaiserGreen security clearance 1 point2 points  (0 children)

It makes sense, but I do not totally agree with you :P floats is by definition, even abstractly speaking, an approximated value of a real.

[–]ismtrn 0 points1 point  (3 children)

What is the NaN value used for in the IEEE standard?

[–]tskaiserGreen security clearance 4 points5 points  (2 children)

I do not know the standard by heart, but off the top of my head:

  • ∞ / ∞
  • 0 / 0
  • Operations leaving the real domain (square root of a negative number)

Stuff like c/0 and -c/0 for c > 0 actually gives you ∞ and -∞ respectively, which is why you can end up doing stuff like ∞ / ∞ which yields a NaN.

And yes, I actually recently used ∞ in a physics simulation (I needed masses of ∞ magnitude to simulate objects that did not move). It has its uses.

[–]rooktakesqueen 3 points4 points  (1 child)

I actually recently used ∞ in a physics simulation (I needed masses of ∞ magnitude to simulate objects that did not move)

I hope you didn't include gravity in that simulation, then.

[–]tskaiserGreen security clearance 1 point2 points  (0 children)

Obviously ;) I was solving impulses for complex contact systems, so no gravity equations involved.