Skip to content

Commit

Permalink
Fix math imports; drop Math (#80)
Browse files Browse the repository at this point in the history
* Fix math imports; drop Math

* Add changelog entry
  • Loading branch information
JordanMartinez authored Mar 29, 2022
1 parent a3e651c commit 7e0251e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
, "foldable-traversable"
, "integers"
, "lists"
, "math"
, "maybe"
, "newtype"
, "numbers"
Expand Down
20 changes: 10 additions & 10 deletions src/Data/Formatter/Number.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7e0251e

Please sign in to comment.