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

Update to v0.14.0-rc3 #11

Merged
merged 4 commits into from
Oct 23, 2020
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
# - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
- TAG=v0.14.0-rc3
- curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
Expand Down
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"output"
],
"dependencies": {
"purescript-math": "^2.1.0",
"purescript-globals": "^4.0.0",
"purescript-maybe": "^4.0.0"
"purescript-math": "master",
"purescript-globals": "master",
"purescript-maybe": "master"
},
"devDependencies": {
"purescript-console": "^4.2.0",
"purescript-assert": "^4.1.0"
"purescript-console": "master",
"purescript-assert": "master"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test": "pulp test"
},
"devDependencies": {
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"pulp": "^15.0.0",
"purescript-psa": "^0.8.0",
"rimraf": "^2.6.1"
}
}
10 changes: 5 additions & 5 deletions src/Data/Number.purs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ import Global as G
-- | > fromString " 1.2 ??"
-- | (Just 1.2)
-- | ```
fromString String Maybe Number
fromString :: String -> Maybe Number
fromString = G.readFloat >>> check
where
check num | isFinite num = Just num
| otherwise = Nothing

-- | Not a number (NaN).
nan Number
nan :: Number
nan = G.nan

-- | Test whether a `Number` is NaN.
isNaN Number Boolean
isNaN :: Number -> Boolean
isNaN = G.isNaN

-- | Positive infinity.
infinity Number
infinity :: Number
infinity = G.infinity

-- | Test whether a number is finite.
isFinite Number Boolean
isFinite :: Number -> Boolean
isFinite = G.isFinite
10 changes: 5 additions & 5 deletions src/Data/Number/Approximate.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ newtype Fraction = Fraction Number
-- | > (eqRelative (Fraction 0.01)) (0.1 + 0.2) 0.3
-- | true
-- | ```
eqRelative Fraction Number Number Boolean
eqRelative :: Fraction -> Number -> Number -> Boolean
eqRelative (Fraction frac) 0.0 y = abs y <= frac
eqRelative (Fraction frac) x 0.0 = abs x <= frac
eqRelative (Fraction frac) x y = abs (x - y) <= frac * abs (x + y) / 2.0
Expand All @@ -60,17 +60,17 @@ eqRelative (Fraction frac) x y = abs (x - y) <= frac * abs (x + y) / 2.0
-- | > 0.1 + 0.2 ≅ 0.3
-- | true
-- | ```
eqApproximate Number Number Boolean
eqApproximate :: Number -> Number -> Boolean
eqApproximate = eqRelative onePPM
where
onePPM Fraction
onePPM :: Fraction
onePPM = Fraction 1.0e-6

infix 4 eqApproximate as ~=
infix 4 eqApproximate as ≅

-- | The complement of `eqApproximate`.
neqApproximate Number Number Boolean
neqApproximate :: Number -> Number -> Boolean
neqApproximate x y = not (x ≅ y)

infix 4 neqApproximate as ≇
Expand All @@ -91,6 +91,6 @@ newtype Tolerance = Tolerance Number
-- | > (eqAbsolute (Tolerance 0.1)) 133.7 133.0
-- | false
-- | ```
eqAbsolute Tolerance Number Number Boolean
eqAbsolute :: Tolerance -> Number -> Number -> Boolean
eqAbsolute (Tolerance tolerance) x y = abs (x - y) <= tolerance

16 changes: 8 additions & 8 deletions src/Data/Number/Format.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ module Data.Number.Format

import Prelude

foreign import toPrecisionNative Int Number String
foreign import toFixedNative Int Number String
foreign import toExponentialNative Int Number String
foreign import toPrecisionNative :: Int -> Number -> String
foreign import toFixedNative :: Int -> Number -> String
foreign import toExponentialNative :: Int -> Number -> String

-- | The `Format` data type specifies how a number will be formatted.
data Format
Expand All @@ -42,21 +42,21 @@ data Format

-- | Create a `toPrecision`-based format from an integer. Values smaller than
-- | `1` and larger than `21` will be clamped.
precision Int Format
precision :: Int -> Format
precision = Precision <<< clamp 1 21

-- | Create a `toFixed`-based format from an integer. Values smaller than `0`
-- | and larger than `20` will be clamped.
fixed Int Format
fixed :: Int -> Format
fixed = Fixed <<< clamp 0 20

-- | Create a `toExponential`-based format from an integer. Values smaller than
-- | `0` and larger than `20` will be clamped.
exponential Int Format
exponential :: Int -> Format
exponential = Exponential <<< clamp 0 20

-- | Convert a number to a string with a given format.
toStringWith Format Number String
toStringWith :: Format -> Number -> String
toStringWith (Precision p) = toPrecisionNative p
toStringWith (Fixed p) = toFixedNative p
toStringWith (Exponential p) = toExponentialNative p
Expand All @@ -73,4 +73,4 @@ toStringWith (Exponential p) = toExponentialNative p
-- | > toString 1.2e-10
-- | "1.2e-10"
-- | ```
foreign import toString Number String
foreign import toString :: Number -> String
4 changes: 2 additions & 2 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import Test.Assert (assertTrue', assertFalse', assertEqual)


-- | Comparison up to 10% relative error.
eqRelative' Number Number Boolean
eqRelative' :: Number -> Number -> Boolean
eqRelative' = eqRelative (Fraction 0.1)

infix 1 eqRelative' as ~=

-- | Comparison up to 0.1 absolute error.
eqAbsolute' Number Number Boolean
eqAbsolute' :: Number -> Number -> Boolean
eqAbsolute' = eqAbsolute (Tolerance 0.1)

infix 1 eqAbsolute' as =~=
Expand Down