Small math function library
smath
can be installed from the official npm package repository. It is highly recommended to install the latest version.
npm i smath@latest
Example: A temperature conversion tool using SMath.translate
to convert units and SMath.approx
to validate the result. The translation uses freezing and boiling points for 2 unit systems to linearly interpolate between them.
import { SMath } from 'smath';
// Define some constants to
// define the number ranges
const C_Freeze = 0,
C_Boil = 100,
F_Freeze = 32,
F_Boil = 212;
// Use the `SMath` class to
// translate the temperature in the
// C number range to a temperature
// in the F number range
const C = 20,
F_expected = 68,
F_actual = SMath.translate(C, C_Freeze, C_Boil, F_Freeze, F_Boil);
// Determine whether the
// temperature conversion
// is valid using `approx`
const valid = SMath.approx(F_expected, F_actual);
if (!valid) {
throw new Error('Invalid result.');
}
Visit the official documentation to learn more!
smath
is an open source software package hosted on a GitHub repository. Bug reports and feature requests can be submitted in issues. Contributions are also accepted by submitting a pull request. Please follow the code styling if submitting a pull request.