diff --git a/src/Basics.elm b/src/Basics.elm index 477048bd..4ef740d7 100644 --- a/src/Basics.elm +++ b/src/Basics.elm @@ -10,7 +10,7 @@ module Basics exposing , pi, cos, sin, tan, acos, asin, atan, atan2 , degrees, radians, turns , toPolar, fromPolar - , isNaN, isInfinite + , isNaN, isInfinite, isPositiveInfinity, isNegativeInfinity , identity, always, (<|), (|>), (<<), (>>), Never, never ) @@ -52,7 +52,7 @@ things. @docs toPolar, fromPolar # Floating Point Checks -@docs isNaN, isInfinite +@docs isNaN, isInfinite, isPositiveInfinity, isNegativeInfinity # Function Helpers @docs identity, always, (<|), (|>), (<<), (>>), Never, never @@ -828,6 +828,27 @@ isInfinite = Elm.Kernel.Basics.isInfinite +{-| Determine whether a float is equal to positive infinity. + + isPositiveInfinity 1 == False + isPositiveInfinity (1/0) == True + isPositiveInfinity -(1/0) == False +-} +isPositiveInfinity : Float -> Bool +isPositiveInfinity = + Elm.Kernel.Basics.isPositiveInfinity + + +{-| Determine whether a float is equal to positive infinity. + + isNegativeInfinity 1 == False + isNegativeInfinity (1/0) == False + isNegativeInfinity -(1/0) == True +-} +isNegativeInfinity : Float -> Bool +isNegativeInfinity = + Elm.Kernel.Basics.isNegativeInfinity + -- FUNCTION HELPERS diff --git a/src/Elm/Kernel/Basics.js b/src/Elm/Kernel/Basics.js index 049291f9..f0ee5e82 100644 --- a/src/Elm/Kernel/Basics.js +++ b/src/Elm/Kernel/Basics.js @@ -47,6 +47,8 @@ var _Basics_atan2 = F2(Math.atan2); function _Basics_toFloat(x) { return x; } function _Basics_truncate(n) { return n | 0; } function _Basics_isInfinite(n) { return n === Infinity || n === -Infinity; } +function _Basics_isPositiveInfinity(n) { return n === Infinity; } +function _Basics_isNegativeInfinity(n) { return n === -Infinity; } var _Basics_ceiling = Math.ceil; var _Basics_floor = Math.floor; diff --git a/src/List.elm b/src/List.elm index 83f411c0..ab9e92a2 100644 --- a/src/List.elm +++ b/src/List.elm @@ -62,7 +62,11 @@ singleton value = -} repeat : Int -> a -> List a repeat n value = - repeatHelp [] n value + if isPositiveInfinity n then + [] + + else + repeatHelp [] n value repeatHelp : List a -> Int -> a -> List a