
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
utils for safe arithmetics around floating point numbers
SafeMaths provides utility function to carry out arithmetic operations such as multiplication, addition and subtraction
// addition
console.log(0.1 + 0.2) // 0.30000000000000004
console.log(safeAdd(0.1,0.2)) // 0.3 ✅
// subtraction
console.log(0.3 - 0.1) // 0.19999999999999998
console.log(safeSubtract(0.3,0.1)) // 0.2 ✅
// multiplication
console.log(0.1 * 0.4) // 0.04000000000000001
console.log(safeSubtract(0.1,0.4)) // 0.04 ✅
If any issue or bugs found while using SafeMaths do open an issue and report it there.
$ yarn add safe-mts
$ npm install safe-mts
Takes two numbers and 'safely' adds them.
Example
import { safeAdd } from "safe-mts";
console.log(0.1 + 0.7) // 0.7999999999999999
console.log(safeAdd(0.1,0.7)) // 0.8 ✅
Example
import { safeSubtract } from "safe-mts";
console.log(0.7 - 0.2) // 0.49999999999999994
console.log(safeAdd(0.7,0.2)) // 0.5 ✅
Takes two numbers and 'safely' multiplies them.
Example
import { safeMultiply } from "safe-mts";
console.log(0.1 * 0.7) // 0.06999999999999999
console.log(safeMultiply(0.1,0.7)) // 0.07 ✅
Returns the number of decimal places of a number. i.e 1 if 1dp, 2 if 2dp and so on.
Example
import { decimalCount } from "safe-mts";
console.log(decimalCount(0.1)) // 1
console.log(decimalCount(0.01)) // 2
console.log(decimalCount(0.001)) // 3
console.log(decimalCount(0.0001)) // 4
FAQs
Safe arithmetics around floating point numbers
The npm package safe-mts receives a total of 6 weekly downloads. As such, safe-mts popularity was classified as not popular.
We found that safe-mts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.