Option to error on nan

As a Roblox developer, it is currently too hard to debug where nan happens
Sometimes I will get a nan because in some way my velocity,orientation,rotvelocity,position,camera lookvector,and ground normal all match up in one specific way
This can be hard to replicate and I’ve spent 10s of minutes trying to get it right again because I am tired and I don’t want to look through all the code to understand where it breaks (or I might not even be aware of the specific edge case that returns nan)

It’s been proposed before to always throw an error when nan is present, but I understand this is disruptive and nan may have some uses because it’s the only value where rawequal(x,x) is false

So instead I’d like it if there were a way to turn on nan for the specific thread like debug.profilebegin and to turn it off, debug.profileend

This would help a lot with debugging

2 Likes

This makes no sense to have as a feature; you should just do sanity checking on your inputs before feeding them through division/unit/other operations that can result into NaN. Your math is incorrect if your computation can result in NaN, and you can use basic debugging to find out where (if num ~= num then error("NaN!") end).

2 Likes

Yeah. I have edge cases I don’t account for properly that produce nan outputs.
Checking for nan after each operation is tedious, and so is manually going through the code logic a hundred times to understand where nan happens

Again, last night it took me like 20 minutes just to reproduce the nan that occured while I was playing around

1 Like