From e4c7a944b4457c9cbc40f58796acf7b5ed924ba7 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Wed, 14 Oct 2020 03:05:43 +0100 Subject: [PATCH] Don't rely on inlining of Ord Number in unsafeClamp --- src/Data/Int.purs | 5 ++--- test/Test/Data/Int.purs | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/Int.purs b/src/Data/Int.purs index 9d685ac..be428f2 100644 --- a/src/Data/Int.purs +++ b/src/Data/Int.purs @@ -27,7 +27,7 @@ import Prelude import Data.Int.Bits ((.&.)) import Data.Maybe (Maybe(..), fromMaybe) -import Global (infinity) +import Global (isFinite) import Math as Math @@ -65,8 +65,7 @@ round = unsafeClamp <<< Math.round -- | This function will return 0 if the input is `NaN` or an `Infinity`. unsafeClamp :: Number -> Int unsafeClamp x - | x == infinity = 0 - | x == -infinity = 0 + | not (isFinite x) = 0 | x >= toNumber top = top | x <= toNumber bottom = bottom | otherwise = fromMaybe 0 (fromNumber x) diff --git a/test/Test/Data/Int.purs b/test/Test/Data/Int.purs index 4f05928..80e1f3e 100644 --- a/test/Test/Data/Int.purs +++ b/test/Test/Data/Int.purs @@ -56,6 +56,7 @@ testInt = do let testNonNumber f = do assert $ f nan == 0 assert $ f infinity == 0 + assert $ f (-infinity) == 0 testNonNumber round testNonNumber ceil