Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document saturating behavior of addition and multiplication #13

Merged
merged 2 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ install:
- npm install purescript pulp bower purescript-psa
- bower install
script:
- pulp build --censor-lib
- pulp build -- --censor-lib
- pulp test
24 changes: 23 additions & 1 deletion src/Data/Int53.purs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,29 @@ instance genericInt53 :: Generic Int53 where

fromSpine _ = Nothing


-- | Addition is saturating:
-- |
-- | ```
-- | >>> top + fromInt 1 == top
-- | true
-- | ```
-- |
-- | NOTE: Due to this, Int53 doesn't actually satisfy the associativity law
-- | for addition:
-- |
-- | ```
-- | >>> top + (fromInt 1 + fromInt (-1))
-- | (Int53 9007199254740991.0)
-- | >>> (top + fromInt 1) + fromInt (-1)
-- | (Int53 9007199254740990.0)
-- | ```
-- |
-- | Multiplication is also saturating:
-- |
-- | ```
-- | >>> top * fromInt 2 == top
-- | true
-- | ```
instance semiringInt53 :: Semiring Int53 where
add (Int53 a) (Int53 b) = unsafeClamp $ add a b
zero = Int53 zero
Expand Down