
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
Arbitrary-length arithmetics without hassle.
bcmath package is a robust solution for calculations when precision is key.
import {Bcmath} from 'bcmath'
// Spawn a bcmath instance with a precision of 20 decimal places
const math = Bcmath(20)
console.log(0.1 + 0.2 + 0.3)
// 0.6000000000000001 :-(
console.log(math.chain(0.1).add(0.2).add(0.3).done())
// 0.6 :-)
console.log(math.eval('x ^ (y + 5)', {x: 2, y: 3}))
// 256
console.log(math.pow(2, 4096).length)
// 1234
const n = math.chain(0.15, 50).pow(-10)
console.log(n.done())
// 173415299.15832613592101475046148114277972531287574726074779
console.log(n.round(3).done())
//173415299.158
console.log(n.round(-3).done())
//173415000
console.log(math.max(1, 2, 3.62, 3.61))
// 3.62
console.log(math.pi(50))
// 3.14159265358979323846264338327950288419716939937510
console.log(math.sqrt(2))
// 1.41421568627450980392
Get a BcmathClass instance
| Name | Type | Description | |
|---|---|---|---|
| scale | int | Decimal places |
BcmathClassBcmath
VoidConstructor
| Name | Type | Description | |
|---|---|---|---|
| scale | int | Decimal places |
VoidReturns Chain object
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number to start with | |
| scale | int | Number of decimal places |
ChainReturns: -1 if left is lesser than right 0 if left is equal to right 1 if left is greater than right
| Name | Type | Description | |
|---|---|---|---|
| left | string number BigInt | Left operand | |
| right | string number BigInt | Right operand |
intNumber to be raised to a power
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number | |
| power | int | Power |
number| Name | Type | Description | |
|---|---|---|---|
| numbers |
stringRound the number to the nearest round number
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number | |
| precision | Number of decimal places. Can be negative. Default: 0 |
stringReturns the absolute value of the specified number
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt |
stringRound the number down
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Subject number | |
| precision | Number of decimal places. Can be negative. Default: 0 |
stringRound the number up
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Subject number | |
| precision | int | Number of decimal places. Can be negative. Default: 0 |
stringMultiply
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | ||
| multiplier | string number BigInt | ||
| scale | int | Number of decimal places |
stringDivide
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number | |
| divisor | string number BigInt | Divisor | |
| scale | int | Number of decimal places |
stringAdd two numbers
| Name | Type | Description | |
|---|---|---|---|
| left | string number BigInt | Left operand | |
| right | string number BigInt | Right operand | |
| scale | int | Number of decimal places |
stringGet the modulus
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number | |
| divisor | Divisor |
stringSubstract right from left
| Name | Type | Description | |
|---|---|---|---|
| left | Left operand | ||
| right | Right operand | ||
| scale | int | Number of decimal places |
stringReturns the highest number
| Name | Type | Description | |
|---|---|---|---|
| ...numbers | Array of numbers | ||
| scale | int | Number of decimal places |
stringReturns the lowest number
| Name | Type | Description | |
|---|---|---|---|
| ...numbers | Array of numbers | ||
| scale | int | Number of decimal places |
stringCheck if the number fits in a signed BigInt
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number |
booleanCheck if the number is safe to use in Javascript BigInt
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number |
booleanGenerator.<number>Get π
| Name | Type | Description | |
|---|---|---|---|
| scale | int | Number of decimal places |
stringπ in a formatted string, up to 50 digits per line
| Name | Type | Description | |
|---|---|---|---|
| scale | int | Number of decimal places |
stringCalculate square root
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | ||
| scale | int |
stringMultiply by -1
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number |
VoidEvaluate an expression
| Name | Type | Description | |
|---|---|---|---|
| expr | string | Expression, e.g 'x + y' | |
| variables | object |
Void| Name | Type | Description | |
|---|---|---|---|
| expr |
function(*): *Trims empty decimal places
| Name | Type | Description | |
|---|---|---|---|
| value |
stringConstructor
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number | |
| scale | int | Number of decimal places (default: 10) |
VoidtoJSON
stringSet the scale of operations
| Name | Type | Description | |
|---|---|---|---|
| scale | int | Number of decimal places |
ChainReturns: -1 if current value is lesser than the number 0 if left is equal to the number 1 if left is greater than the number
| Name | Type | Description | |
|---|---|---|---|
| left | Left operand | ||
| right | Right operand |
intRound value to the nearest round number
| Name | Type | Description | |
|---|---|---|---|
| precision | Number of decimal places. Can be negative. Default: 0 |
ChainRound the number down
| Name | Type | Description | |
|---|---|---|---|
| precision | Number of decimal places. Can be negative. Default: 0 |
ChainRound the number up
| Name | Type | Description | |
|---|---|---|---|
| precision | Number of decimal places. Can be negative. Default: 0 |
ChainPow
| Name | Type | Description | |
|---|---|---|---|
| power |
ChainMultiply
| Name | Type | Description | |
|---|---|---|---|
| value |
ChainDivide value by a divisor
| Name | Type | Description | |
|---|---|---|---|
| divisor | Divisor |
ChainSubstract a number
| Name | Type | Description | |
|---|---|---|---|
| number | string number BigInt | Number to add |
ChainAdd a number
| Name | Type | Description | |
|---|---|---|---|
| value |
ChainReturns the highest number
| Name | Type | Description | |
|---|---|---|---|
| numbers | string number BigInt | Array of numbers |
ChainReturns the lowest number
| Name | Type | Description | |
|---|---|---|---|
| numbers | string number BigInt | Array of numbers |
ChainReturns the absolute value of the specified number
ChainReturn the final value of the chain
| Name | Type | Description | |
|---|---|---|---|
| plus | If true, positive number will be prepended by + sign. Default: false |
stringGet the raw value
Documentation generated with doxdox.
FAQs
Arbitrary-length arithmetics API based on locutus/php/bcmath
The npm package bcmath receives a total of 127 weekly downloads. As such, bcmath popularity was classified as not popular.
We found that bcmath 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.