根据此文档:http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#isNaN,Elm支持无穷大并将其视为数字。目前我正在使用inf = 1/0作为常量,但我想知道如何导入无穷大,而不是定义它。因此,Elm是否有一个表示无穷大的常量,我应该如何导入它?
我看到你已经有了一个答案,但是这里有一种使用Maybe
来模拟无穷大的方法。
infinity =
Nothing
lessThan : Int -> Maybe Int -> Maybe Int
lessThan x y =
case y of
Just y_ ->
if x < y_ then
Just x
else
y
Nothing ->
Just x
type MaybeInfiniteInt
= Finite Int
| Infinite
min : Int -> MaybeInfiniteInt -> MaybeInfiniteInt
min xInt y =
case y of
Finite yInt ->
if xInt < yInt then
Finite xInt
else
y
Infinte ->
Finite xInt
{-| Note the argument order is designed for reading in a pipe: y |> moreThan x
-}
moreThan : Int -> MaybeInfiniteInt -> MaybeInfiniteInt
moreThan xInt y =
case y of
Finite yInt ->
yInt > xint
Infinte ->
True
isInfinite
来检查任何一个Float
的值。http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Basics#isInfinite - wintvelt