Java数学-NaN测试 [英] Java maths - testing for NaN
问题描述
对于要导致分配NaN
的任何代码,我希望具有某种项目范围的快速故障排除机制(可能是RuntimeException
).
I would like to have some kind of project-wide fail fast mechanism (maybe a RuntimeException
) for any code that causes assignment of NaN
.
在我的项目中,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.
推荐答案
是的,只要将值设置为NaN,就可以使用AspectJ(面向方面的编程)引发错误.
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.
这篇关于Java数学-NaN测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!