1.2.3 • Published 11 months ago

math-exact-result v1.2.3

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Math Exact Result (Math Floating Point)

This package gives only arithmetic simple operations addition, subtraction, multiplication, and division which return the correct arithmetic result.

Examples

addition

import { add } from 'math-exact-ersult';

add(12, 34); // 46
add('12', 34); // 46
add('12', '34'); // 46
add(0.1, 0.2); // 0.3
add(11, 45, 0.1, 31.5); // 87.6
add(-66, 42); // -24
add(-23, -57); // -80

subtraction

import { subtract } from 'math-exact-ersult';

subtract(34, 12); // 22
subtract('43', 11); // 32
subtract('56', '223'); // -167
subtract(0.2, 0.1); // 0.1
subtract(84, 24, 0.3); // 59.7
subtract(-76, 42); // -118
subtract(-80, -34); // -46

multiplication

import { multiply } from 'math-exact-ersult';

multiply(4, 5); // 20
multiply('43', 3); // 129
multiply('2', '12'); // 24
multiply(0.2, 0.1); // 0.02
multiply(4, 55, 0.3); // 66
multiply(-7, 4); // -28
multiply(-32, -5); // -160

division

import { divide } from 'math-exact-ersult';

divide(24, 6); // 4
divide('48', 8); // 6
divide('27', '3'); // 9
divide(0.4, 0.2); // 2
divide(128, 2, 4); // 16
divide(87, 5.4); // 16,11111111111111
divide(-28, 4); // -7
divide(-32, -6); // -4

Difference between pure javascript and 'math-exact-result'

typeoperationjavascriptmath-exact-result
addition0.2 + 0.10.300000000000000040.3
subtraction0.3 - 0.10.199999999999999980.2
multiplication0.1 * 0.70.069999999999999990.07
division0.3 / 60.0499999999999999960.05