Haskell: comparing NaN values

萝らか妹 提交于 2019-12-02 11:53:19

问题


I wrote quickcheck tests for a Haskell program that optimizes and evaluates a function.

The problem is quickcheck generates expressions resulting in NaN like:

> acos(2)
NaN

Haskell evaluates the following statement as false:

> acos(2)==acos(2)
False

So my quickcheck tests fail with this comparison. Is there any way to compare NaN values?


回答1:


No, as is defined by IEEE 754 comparing 2 NaNs always return false. To chceck if your value is NaN in Haskell you can use isNaN method or write it by yourself

isNaN' :: a -> Bool
isNaN' a = a /= a


来源:https://stackoverflow.com/questions/19809908/haskell-comparing-nan-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!