Skip to content

Commit fa3f258

Browse files
Add toNumber and divide
1 parent 01aec12 commit fa3f258

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spago.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
, "enums"
66
, "fast-vect"
77
, "foldable-traversable"
8+
, "integers"
89
, "maybe"
910
, "partial"
1011
, "prelude"

src/Data/Int/AtLeast.purs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ module Data.Int.AtLeast
33
, fromInt
44
, fromInt'
55
, toInt
6+
, toNumber
67
, (%+%), plus
78
, (%-%), minus
89
, (%*%), times
910
, (%/%), quotient
1011
, modulo
1112
, remainder
13+
, divide
1214
, weaken
1315
, strengthen
1416
, gcd
@@ -24,6 +26,7 @@ import Data.Array (length) as Array
2426
import Data.Array.NonEmpty (NonEmptyArray, cons', length, singleton) as NEA
2527
import Data.Enum (class Enum)
2628
import Data.EuclideanRing (gcd) as Int
29+
import Data.Int (toNumber) as Int
2730
import Data.Maybe (Maybe(Nothing, Just))
2831
import Data.Reflectable (class Reflectable, reflectType)
2932
import Partial (crashWith)
@@ -84,6 +87,10 @@ fromInt' i =
8487
toInt :: (min :: Int). IntAL min -> Int
8588
toInt (IntAL i) = i
8689

90+
-- | Convert an `IntAL` to a Number
91+
toNumber :: (min :: Int). IntAL min -> Number
92+
toNumber (IntAL i) = Int.toNumber i
93+
8794
-- | Add two IntAL values with possibly different type-level minimums
8895
plus
8996
:: (min_i :: Int) (min_j :: Int) (min_sum :: Int)
@@ -130,7 +137,7 @@ quotient (IntAL i) (IntAL j) = IntAL $ div i j
130137
infixl 7 quotient as %/%
131138

132139
-- | Compute the remainder after division of one `IntAL` by another, returning
133-
-- | an `IntAL 0`. Similar to `mod` by accepts and returns `IntAL`
140+
-- | an `IntAL 0`. Similar to `mod` by accepts and returns `IntAL 0`
134141
modulo :: (min_i :: Int) (min_j :: Int). IntAL min_i -> IntAL min_j -> IntAL 0
135142
modulo (IntAL i) (IntAL j) = remainder i j
136143

@@ -139,6 +146,10 @@ modulo (IntAL i) (IntAL j) = remainder i j
139146
remainder :: Int -> Int -> IntAL 0
140147
remainder i j = IntAL (mod i j)
141148

149+
-- | Divide one `IntAL` by another, returning a Number
150+
divide :: (min_i :: Int) (min_j :: Int). IntAL min_i -> IntAL min_j -> Number
151+
divide i j = toNumber i / toNumber j
152+
142153
-- | Decrease the type-level minimum value without changing the runtime value
143154
weaken
144155
:: (min_from :: Int) (min_to :: Int) (min_from_plus_one :: Int)

0 commit comments

Comments
 (0)