New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lambda-math

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-math

Pseudo lambda expressions for JS arbitrary-precision arithmetic operations.

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Lambda math

Build Status npm version

Pseudo lambda expressions for JS arbitrary-precision arithmetic operations.

Install

npm install --save lambda-math

Example

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:

const { div, add, λ, _ } = require('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).

Internals

Besides adding pseudo syntactic sugar, lambda-math uses bignumber.js under the hood for actual arbitrary-precision decimal arithmetic.

License

See LICENSE for more details.

FAQs

Package last updated on 12 May 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc