How to produce infinity in Haskell?

戏子无情 提交于 2019-12-04 04:28:31

问题


Similarily to How to produce a NaN in Haskell ...

In C, there is the INFINITY macro, defined by math.h.

Again, in http://hackage.haskell.org/package/ClassyPrelude-0.1/docs/Prelude-Math.html I can see falicities to test for infnity, but not to produce one.

Therefore, is my only choice something like 1/0?


回答1:


The iee754 package has functions and constants specific to that floating point format.

In particular, it has the Numeric.IEEE.infinity constant for members for the IEEE class (which float and double belong to). It is pretty much just implemented as 1/0 though, so your call if you want the package dependency for a prettier name.



来源:https://stackoverflow.com/questions/55902725/how-to-produce-infinity-in-haskell

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