Skip to content

Commit 626e299

Browse files
Move examples from README.md to Data.Number
1 parent 261ffbc commit 626e299

File tree

2 files changed

+201
-176
lines changed

2 files changed

+201
-176
lines changed

README.md

Lines changed: 17 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -12,168 +12,23 @@ Utility functions for working with PureScripts builtin `Number` type.
1212
spago install numbers
1313
```
1414

15-
## Examples
16-
17-
Parsing:
18-
19-
```purs
20-
> fromString "12.34"
21-
(Just 12.34)
22-
23-
> fromString "1e-3"
24-
(Just 0.001)
25-
```
26-
27-
Formatting (`Data.Number.Format`):
28-
29-
```purs
30-
> let x = 1234.56789
31-
32-
> toStringWith (precision 6) x
33-
"1234.57"
34-
35-
> toStringWith (fixed 3) x
36-
"1234.568"
37-
38-
> toStringWith (exponential 2) x
39-
"1.23e+3"
40-
```
41-
42-
Approximate comparisons (`Data.Number.Approximate`):
43-
44-
```purs
45-
> 0.1 + 0.2 == 0.3
46-
false
47-
48-
> 0.1 + 0.2 ≅ 0.3
49-
true
50-
```
51-
52-
_NaN_ and _infinity_:
53-
54-
```purs
55-
> isNaN (Math.asin 2.0)
56-
true
57-
58-
> isFinite (1.0 / 0.0)
59-
false
60-
```
61-
62-
Remainder:
63-
```purs
64-
> 5.3 % 2.0
65-
1.2999999999999998
66-
```
67-
68-
Trignometric functions:
69-
```purs
70-
> sin 0.0
71-
0.0
72-
73-
> cos 0.0
74-
1.0
75-
76-
> tan 0.0
77-
0.0
78-
```
79-
80-
Inverse trignometric functions:
81-
```purs
82-
> asin 0.0
83-
0.0
84-
85-
> acos 0.0 - pi / 2.0
86-
0.0
87-
88-
> atan 0.0
89-
0.0
90-
91-
> atan2 0.0 1.0
92-
0.0
93-
```
94-
95-
Natural logarithm and exponent:
96-
```purs
97-
> log (exp 42.0)
98-
42.0
99-
```
100-
101-
Square root and powers:
102-
```purs
103-
> sqrt (42.0 `pow` 2.0)
104-
42.0
105-
```
106-
107-
Rounding functions:
108-
```purs
109-
> x = 1.5
110-
> ceil x
111-
2.0
112-
113-
> floor x
114-
1.0
115-
116-
> round x
117-
2.0
118-
119-
> trunc x
120-
1.0
121-
```
122-
123-
Numeric minimum and maximum:
124-
```purs
125-
> import Data.Number as Num
126-
> import Data.Ord as Ord
127-
> Num.min 0.0 1.0
128-
0.0
129-
130-
> Num.max 0.0 1.0
131-
1.0
132-
133-
> Num.min Num.nan 0.0
134-
NaN
135-
136-
> Ord.min Num.nan 0.0
137-
0.0
138-
```
139-
140-
Constants:
141-
```purs
142-
> e
143-
2.718281828459045
144-
145-
> ln 2
146-
0.6931471805599453
147-
148-
> ln10
149-
2.302585092994046
150-
151-
> log10e
152-
0.4342944819032518
153-
154-
> log2e
155-
1.4426950408889634
156-
157-
> pi
158-
3.141592653589793
159-
160-
> sqrt1_2
161-
0.7071067811865476
162-
163-
> sqrt2
164-
1.4142135623730951
165-
166-
> tau
167-
6.283185307179586
168-
```
169-
170-
Sign and absolute value:
171-
```purs
172-
> x = -42.0
173-
> sign x * abs x == x
174-
true
175-
```
176-
15+
## Scope
16+
17+
* Parsing with `fromString`
18+
* Formating with `toStringWith`, see `Data.Number.Format`
19+
* Approximate comparisions with ``, see `Data.Number.Approximate`
20+
* Not-a-number and infinite value detection with `isNaN` and `isFinite`
21+
* Remainder with `%`
22+
* Trignometric functions with `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, and
23+
`atan2`
24+
* Natural logarithm and exponents with `log` and `exp`
25+
* Powers with `sqrt` and `pow`
26+
* Rounding with `ceil`, `floor`, `round`, and `trunc`
27+
* Numeric minimum and maximum with `min` and `max`, which behave differently to
28+
the versions in `Data.Ord` on values of `NaN`
29+
* Sign and absolute value functions `sign` and `abs`
30+
* Numeric constants `e`, `ln 2`, `ln10`, `log10e`, `log2e`, `pi`, `sqrt1_2`,
31+
`sqrt2`, and `tau`
17732

17833
## Documentation
17934

0 commit comments

Comments
 (0)