From b66faaa5ddef73c9bd2512e8cfad9e897f125cae Mon Sep 17 00:00:00 2001 From: Jamie Ballingall Date: Tue, 19 Jul 2022 16:45:56 -0400 Subject: [PATCH 1/3] Add minInt and maxInt values --- src/Data/Int.purs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Data/Int.purs b/src/Data/Int.purs index c637fc8..c0f47fd 100644 --- a/src/Data/Int.purs +++ b/src/Data/Int.purs @@ -1,3 +1,5 @@ +-- | Functions for working with PureScript's builtin `Int` type. A `Int` +-- | is a signeed 32-bit integer. module Data.Int ( fromNumber , ceil @@ -31,6 +33,25 @@ import Data.Maybe (Maybe(..), fromMaybe) import Data.Number (isFinite) import Data.Number as Number +-- | The most negative `Int`, equal to -2^31. +-- | ```purs +-- | > minInt +-- | -2147483648 +-- | ``` +minInt :: Int +minInt = -0x80000000 + +-- | The most positive `Int`, equal to 2^31 - 1. +-- | ```purs +-- | > maxInt +-- | 2147483647 +-- | +-- | > maxInt + 1 == minInt +-- | true +-- | ``` +maxInt :: Int +maxInt = 0x7FFFFFFF + -- | Creates an `Int` from a `Number` value. The number must already be an -- | integer and fall within the valid range of values for the `Int` type -- | otherwise `Nothing` is returned. From 88e1c0ff364c91d4446f44dd1bc42929c8d17f8b Mon Sep 17 00:00:00 2001 From: Jamie Ballingall Date: Tue, 19 Jul 2022 21:09:36 -0400 Subject: [PATCH 2/3] Export minInt and maxInt and add tests --- src/Data/Int.purs | 4 +++- test/Test/Data/Int.purs | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Data/Int.purs b/src/Data/Int.purs index c0f47fd..4e0c8e6 100644 --- a/src/Data/Int.purs +++ b/src/Data/Int.purs @@ -1,7 +1,9 @@ -- | Functions for working with PureScript's builtin `Int` type. A `Int` -- | is a signeed 32-bit integer. module Data.Int - ( fromNumber + ( minInt + , maxInt + , fromNumber , ceil , floor , trunc diff --git a/test/Test/Data/Int.purs b/test/Test/Data/Int.purs index 1eabc6b..edafadd 100644 --- a/test/Test/Data/Int.purs +++ b/test/Test/Data/Int.purs @@ -2,7 +2,7 @@ module Test.Data.Int (testInt) where import Prelude -import Data.Int (binary, ceil, even, floor, fromNumber, fromString, fromStringAs, hexadecimal, octal, odd, parity, pow, quot, radix, rem, round, toNumber, toStringAs) +import Data.Int (binary, ceil, even, floor, fromNumber, fromString, fromStringAs, hexadecimal, maxInt, minInt, octal, odd, parity, pow, quot, radix, rem, round, toNumber, toStringAs) import Data.Maybe (Maybe(..), fromJust) import Effect (Effect) import Effect.Console (log) @@ -13,6 +13,15 @@ import Test.Assert (assert) testInt :: Effect Unit testInt = do + log "minInt should be -2147483648" + assert $ minInt == -2147483648 + + log "maxInt should be 2147483647" + assert $ maxInt == 2147483647 + + log "maxInt + 1 should equal minInt" + assert $ maxInt + 1 == minInt + log "fromNumber should coerce integer values" assert $ fromNumber 1.0 == Just 1 assert $ fromNumber 42.0 == Just 42 From 80e83ccc3d4fca865b84420c002dff7adfb73ed3 Mon Sep 17 00:00:00 2001 From: Jamie Ballingall Date: Wed, 20 Jul 2022 12:34:57 -0400 Subject: [PATCH 3/3] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3e590c..9c8feb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Added `minInt` and `maxInt` (#54 by @JamieBallingall) Bugfixes: