From 7e0251e9d588b113bdb65c6adeb144b4984fb7ac Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Tue, 29 Mar 2022 08:57:31 -0500 Subject: [PATCH] Fix math imports; drop Math (#80) * Fix math imports; drop Math * Add changelog entry --- CHANGELOG.md | 1 + spago.dhall | 1 - src/Data/Formatter/Number.purs | 20 ++++++++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61b3080..ea19825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Bugfixes: Other improvements: - Added `purs-tidy` formatter (#77 by @thomashoneyman) +- Drop `math` dependency; update imports (#80 by @JordanMartinez) ## [v6.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v6.0.0) - 2021-10-16 diff --git a/spago.dhall b/spago.dhall index cda9ac8..08b5493 100644 --- a/spago.dhall +++ b/spago.dhall @@ -13,7 +13,6 @@ , "foldable-traversable" , "integers" , "lists" - , "math" , "maybe" , "newtype" , "numbers" diff --git a/src/Data/Formatter/Number.purs b/src/Data/Formatter/Number.purs index cc0a0e2..d0504da 100644 --- a/src/Data/Formatter/Number.purs +++ b/src/Data/Formatter/Number.purs @@ -25,11 +25,11 @@ import Data.Generic.Rep (class Generic) import Data.Int as Int import Data.Maybe (Maybe(..), fromMaybe, isJust) import Data.Newtype (class Newtype) +import Data.Number as Number import Data.Show.Generic (genericShow) import Data.String as Str import Data.String.CodeUnits as CU import Data.Traversable (for) -import Math as Math import Text.Parsing.Parser as P import Text.Parsing.Parser.Combinators as PC import Text.Parsing.Parser.String as PS @@ -95,9 +95,9 @@ foreign import showNumberAsInt :: Number -> String format :: Formatter -> Number -> String format (Formatter f) num = do let - absed = Math.abs num + absed = Number.abs num tens - | absed > 0.0 = max (Int.floor $ Math.log absed / Math.ln10) 0 + | absed > 0.0 = max (Int.floor $ Number.log absed / Number.ln10) 0 | otherwise = 0 if f.abbreviations then do @@ -114,17 +114,17 @@ format (Formatter f) num = do | thousands == 7 = "Z" | thousands == 8 = "Y" | otherwise = "10e+" <> show (thousands * 3) - newNum = if thousands < 1 then num else num / Math.pow 1000.0 (Int.toNumber thousands) + newNum = if thousands < 1 then num else num / Number.pow 1000.0 (Int.toNumber thousands) format (Formatter f { abbreviations = false }) newNum <> abbr else do let zeros = f.before - tens - one - factor = Math.pow 10.0 (Int.toNumber (max 0 f.after)) - rounded = Math.round (absed * factor) / factor - integer = Math.floor rounded + factor = Number.pow 10.0 (Int.toNumber (max 0 f.after)) + rounded = Number.round (absed * factor) / factor + integer = Number.floor rounded leftoverDecimal = rounded - integer - leftover = Math.round $ leftoverDecimal * factor + leftover = Number.round $ leftoverDecimal * factor leftoverWithZeros = do let @@ -232,9 +232,9 @@ unformatParser (Formatter f) = do else pure 0 pure $ - Math.pow 10.0 (Int.toNumber abbr) + Number.pow 10.0 (Int.toNumber abbr) * sign - * (before + after / Math.pow 10.0 (Int.toNumber f.after)) + * (before + after / Number.pow 10.0 (Int.toNumber f.after)) formatNumber :: String -> Number -> Either String String formatNumber pattern number = parseFormatString pattern <#> flip format number