
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
lambda-math
Advanced tools
Pseudo lambda expressions for JS arbitrary-precision arithmetic operations.
Pseudo lambda expressions for JS arbitrary-precision arithmetic operations.
NOTE: Under development. Most of the functionality is still not working.
Consider adding the floating point number 300 / 293
many times. 72 times in fact. Now, we don't want to simply multiply a number by 72. We want to add it 72 times, so that we can clearly see the problem with floating point rounding which exists in standard JavaScript. So, using lambda-math
library, we can write:
import { λ, _, add, div } from 'lambda-math';
λ( div, [300, 293] )
( add, [λ[0], λ[0]], [_, λ[0]], 70 );
console.log(λ[1].number); // 73.72013651877133
Compare the above to the simple JavaScript way of doing such a sum:
let result = 0;
for (let i = 0; i < 72; i += 1) {
result += 300 / 293;
}
console.log(result); // 73.72013651877126
Or, a more functional (fancy) JS approach:
console.log(
Array.from(Array(72).keys()).map(() => { return 300 / 293; }).reduce((a, b) => { return a + b; })
); // 73.72013651877126
As you can see, the pseudo lambda approach doesn't have the problem with rounding floating point numbers. Also, some (mathematicians) can argue that the syntax lambda-math
introduces is more elegant, shorter, and cleaner overall (compared to pure JavaScript way of doing things).
Besides adding pseudo syntactic sugar, lambda-math
uses bignumber.js under the hood for actual arbitrary-precision decimal arithmetic.
FAQs
Pseudo lambda expressions for JS arbitrary-precision arithmetic operations.
The npm package lambda-math receives a total of 1 weekly downloads. As such, lambda-math popularity was classified as not popular.
We found that lambda-math 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.