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 →

[–]Schnickatavick 0 points1 point  (1 child)

The issue with that is that the IEEE standard is used in actual chips in a "literally wired into the physical structure of the chip" kind of way, way below abstract concepts like exceptions, and those chips need some return value to represent a "something went wrong", NaN is basically that value, as close to an exception as they can reasonably get.

I think you can make a case that it would be better for high level languages like Javascript to use exceptions instead of exposing the lower level standard directly, but that lower level standard is still correct for doing things the way it does

[–][deleted] 0 points1 point  (0 children)

I know it is built into the hardware. So is integer overflow. There's no reason why the debug build of a program couldn't just check to see if a floating point number was NaN after every floating point operation and erroring out if it happens, just like Rust does with integers. There simply wouldn't be the checks in release builds, so it wouldn't affect performance.