smath 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ npm i smath@latest
|
|
|
13
13
|
|
|
14
14
|
## Getting Started
|
|
15
15
|
|
|
16
|
-
**Example:** A temperature conversion tool.
|
|
16
|
+
**Example:** A temperature conversion tool using [`SMath.translate`](https://npm.nicfv.com/smath/classes/SMath.html#translate) to convert units and [`SMath.approx`](https://npm.nicfv.com/smath/classes/SMath.html#approx) to validate the result. The translation uses freezing and boiling points for 2 unit systems to linearly interpolate between them.
|
|
17
17
|
|
|
18
18
|
```js
|
|
19
|
-
import { SMath
|
|
19
|
+
import { SMath } from 'smath';
|
|
20
20
|
|
|
21
21
|
// Define some constants to
|
|
22
22
|
// define the number ranges
|
|
@@ -25,20 +25,20 @@ const C_Freeze = 0,
|
|
|
25
25
|
F_Freeze = 32,
|
|
26
26
|
F_Boil = 212;
|
|
27
27
|
|
|
28
|
-
// Use the `
|
|
28
|
+
// Use the `SMath` class to
|
|
29
29
|
// translate the temperature in the
|
|
30
30
|
// C number range to a temperature
|
|
31
31
|
// in the F number range
|
|
32
32
|
const C = 20,
|
|
33
33
|
F_expected = 68,
|
|
34
|
-
F_actual =
|
|
34
|
+
F_actual = SMath.translate(C, C_Freeze, C_Boil, F_Freeze, F_Boil);
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
36
|
+
// Determine whether the
|
|
37
|
+
// temperature conversion
|
|
38
|
+
// is valid using `approx`
|
|
39
39
|
const valid = SMath.approx(F_expected, F_actual);
|
|
40
40
|
if (!valid) {
|
|
41
|
-
throw 'Invalid result.';
|
|
41
|
+
throw new Error('Invalid result.');
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|