Java maths - testing for NaN

java, math, nan

Solution

Yes, you can use AspectJ (aspect oriented programming) to throw an error whenever a value is set to NaN.

Essentially, you want to intercept whenever a value is set, and perform some other function.

We've done similar things in our codebase ... but I can't give you much help outside of that.

Problem

I would like to have some kind of project-wide fail fast mechanism (maybe a `RuntimeException`) for any code that causes assignment of `NaN`. In my project `NaN` is never a valid value. I realise I could add asserts (using isNaN) or other tests throughout but I want to know if there is a more elegant way.

Original source

Related problems