Skip to content

Math migration #18

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

Merged
merged 23 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0b47ae5
Add constants that currently live in purescript-math
JamieBallingall Aug 17, 2021
49fadb1
Add core math functions that currently live in purescript-math. Also …
JamieBallingall Aug 17, 2021
37f1bea
Remove dependency on purescript-math
JamieBallingall Aug 17, 2021
c047653
Update CHANGELOG
JamieBallingall Aug 17, 2021
82fba35
Add sign function
JamieBallingall Aug 17, 2021
730a64b
Update CHANGELOG for sign
JamieBallingall Aug 17, 2021
8bb43d9
Fix issue with sign polyfill
JamieBallingall Aug 23, 2021
c1411d0
Update documentation in README.md and a little in Number.purs
JamieBallingall Aug 23, 2021
e0a4638
Add tests for math functions
JamieBallingall Aug 23, 2021
46504b5
Update CHANGELOG.md with PR number
JamieBallingall Aug 23, 2021
35ae86b
Fix warning and remove extraneous comment in test/Main.purs
JamieBallingall Aug 23, 2021
119cf59
Remove the type synonym Radians
JamieBallingall Aug 23, 2021
6544eeb
Fix comment to remainder
JamieBallingall Aug 23, 2021
07714bf
Fix comment to sqrt1_2
JamieBallingall Aug 23, 2021
91c9a2e
Rework tests in terms of eqAbsolute
JamieBallingall Aug 23, 2021
261ffbc
Merge branch 'math-migration' of https://github.com/JamieBallingall/p…
JamieBallingall Aug 23, 2021
626e299
Move examples from README.md to Data.Number
JamieBallingall Jan 15, 2022
73c1e25
Update trig examples to use pi
JamieBallingall Jan 16, 2022
93346c0
Convert trunc from Purescript to Javascript with polyfill, similar to…
JamieBallingall Mar 2, 2022
345e0e0
Merge remote-tracking branch 'origin/master' into HEAD
JordanMartinez Mar 16, 2022
2d1abdd
Update changelog
JordanMartinez Mar 25, 2022
9f9dc5e
Further tweak changelog
JordanMartinez Mar 25, 2022
4f4326d
Update exp and log docs
JordanMartinez Mar 25, 2022
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Ported various functions & constants from `purescript-math` (#18 by @JamieBallingall)

Specifically...
- `abs`, `sign`
- `max`, `min` (which work differently than `Number`'s `Ord` instance)
- `ceil`, `floor`, `trunc`, `remainder`/`%`, `round`
- `log`
- `exp`, `pow`, `sqrt`
- `acos`, `asin`, `atan`, `atan2`, `cos`, `sin`, `tan`
- Numeric constants: `e`, `ln2`, `ln10`, `log10e`, `log2e`, `pi`, `sqrt1_2`,
`sqrt2`, and `tau`

Bugfixes:

Other improvements:
- Removed dependency on `purescript-math`

## [v8.0.0](https://github.com/purescript/purescript-numbers/releases/tag/v7.0.0) - 2021-02-26

Expand Down
63 changes: 17 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,23 @@ Utility functions for working with PureScripts builtin `Number` type.
spago install numbers
```

## Examples

Parsing:

```purs
> fromString "12.34"
(Just 12.34)

> fromString "1e-3"
(Just 0.001)
```

Formatting (`Data.Number.Format`):

```purs
> let x = 1234.56789

> toStringWith (precision 6) x
"1234.57"

> toStringWith (fixed 3) x
"1234.568"

> toStringWith (exponential 2) x
"1.23e+3"
```

Approximate comparisons (`Data.Number.Approximate`):

```purs
> 0.1 + 0.2 == 0.3
false

> 0.1 + 0.2 ≅ 0.3
true
```

_NaN_ and _infinity_:

```purs
> isNaN (Math.asin 2.0)
true

> isFinite (1.0 / 0.0)
false
```
## Scope

* Parsing with `fromString`
* Formating with `toStringWith`, see `Data.Number.Format`
* Approximate comparisions with `≅`, see `Data.Number.Approximate`
* Not-a-number and infinite value detection with `isNaN` and `isFinite`
* Remainder with `%`
* Trignometric functions with `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, and
`atan2`
* Natural logarithm and exponents with `log` and `exp`
* Powers with `sqrt` and `pow`
* Rounding with `ceil`, `floor`, `round`, and `trunc`
* Numeric minimum and maximum with `min` and `max`, which behave differently to
the versions in `Data.Ord` on values of `NaN`
* Sign and absolute value functions `sign` and `abs`
* Numeric constants `e`, `ln 2`, `ln10`, `log10e`, `log2e`, `pi`, `sqrt1_2`,
`sqrt2`, and `tau`

## Documentation

Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"dependencies": {
"purescript-functions": "master",
"purescript-math": "master",
"purescript-maybe": "master"
},
"devDependencies": {
Expand Down
64 changes: 64 additions & 0 deletions src/Data/Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,67 @@ export function fromStringImpl(str, isFinite, just, nothing) {
return nothing;
}
}

export const abs = Math.abs;

export const acos = Math.acos;

export const asin = Math.asin;

export const atan = Math.atan;

export const atan2 = function (y) {
return function (x) {
return Math.atan2(y, x);
};
};

export const ceil = Math.ceil;

export const cos = Math.cos;

export const exp = Math.exp;

export const floor = Math.floor;

export const log = Math.log;

export const max = function (n1) {
return function (n2) {
return Math.max(n1, n2);
};
};

export const min = function (n1) {
return function (n2) {
return Math.min(n1, n2);
};
};

export const pow = function (n) {
return function (p) {
return Math.pow(n, p);
};
};

export const remainder = function (n) {
return function (m) {
return n % m;
};
};

export const round = Math.round;

export const sign = Math.sign ? Math.sign : function(x) {
return x === 0 || x !== x ? x : (x < 0 ? -1 : 1);
};

export const sin = Math.sin;

export const sqrt = Math.sqrt;

export const tan = Math.tan;

export const trunc = Math.trunc ? Math.trunc : function(x) {
return x < 0 ? Math.ceil(x) : Math.floor(x);
}
Loading