@@ -3,12 +3,14 @@ module Data.Int.AtLeast
3
3
, fromInt
4
4
, fromInt'
5
5
, toInt
6
+ , toNumber
6
7
, (%+%), plus
7
8
, (%-%), minus
8
9
, (%*%), times
9
10
, (%/%), quotient
10
11
, modulo
11
12
, remainder
13
+ , divide
12
14
, weaken
13
15
, strengthen
14
16
, gcd
@@ -24,6 +26,7 @@ import Data.Array (length) as Array
24
26
import Data.Array.NonEmpty (NonEmptyArray , cons' , length , singleton ) as NEA
25
27
import Data.Enum (class Enum )
26
28
import Data.EuclideanRing (gcd ) as Int
29
+ import Data.Int (toNumber ) as Int
27
30
import Data.Maybe (Maybe (Nothing, Just))
28
31
import Data.Reflectable (class Reflectable , reflectType )
29
32
import Partial (crashWith )
@@ -84,6 +87,10 @@ fromInt' i =
84
87
toInt :: ∀ (min :: Int ). IntAL min -> Int
85
88
toInt (IntAL i) = i
86
89
90
+ -- | Convert an `IntAL` to a Number
91
+ toNumber :: ∀ (min :: Int ). IntAL min -> Number
92
+ toNumber (IntAL i) = Int .toNumber i
93
+
87
94
-- | Add two IntAL values with possibly different type-level minimums
88
95
plus
89
96
:: ∀ (min_i :: Int ) (min_j :: Int ) (min_sum :: Int )
@@ -130,7 +137,7 @@ quotient (IntAL i) (IntAL j) = IntAL $ div i j
130
137
infixl 7 quotient as %/%
131
138
132
139
-- | 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 `
134
141
modulo :: ∀ (min_i :: Int ) (min_j :: Int ). IntAL min_i -> IntAL min_j -> IntAL 0
135
142
modulo (IntAL i) (IntAL j) = remainder i j
136
143
@@ -139,6 +146,10 @@ modulo (IntAL i) (IntAL j) = remainder i j
139
146
remainder :: Int -> Int -> IntAL 0
140
147
remainder i j = IntAL (mod i j)
141
148
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
+
142
153
-- | Decrease the type-level minimum value without changing the runtime value
143
154
weaken
144
155
:: ∀ (min_from :: Int ) (min_to :: Int ) (min_from_plus_one :: Int )
0 commit comments