npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lzwme/asmd-calc

v1.3.2

Published

支持浮点数精度的加减乘除四则运算 JS 库。

Downloads

19

Readme

@lzwme/asmd-calc

@lzwme/asmd-calc

build status NPM version node version npm download GitHub issues GitHub forks GitHub stars license MIT

简体中文

A short and concise JavaScript library for the four fundamental operations of arithmetic, which supports the addition, subtraction, multiplication and division calculation of floating-point precision.

Features

  • Short and sharp. It only includes the calculation of addition, subtraction, multiplication and division. The core code is less than 100 lines. There is no other dependency.
  • High execution performance. Only the four operations that can be accurately expressed by the front end are considered to realize simple logic and better execution performance than the open source library with rich and complex functions (see Benchmark for details).
  • Accurate and stable. The accumulation of many years of practical experience in the development of several financial trading systems covers various common calculation use case error scenarios.

Not Applicable

  • For numerical processing involving very large numbers that front-end can not be accurately represented.
  • Complex mathematical scientific calculation.

These libraries are recommended:

Install

# npm
npm i @lzwme/asmd-calc
# yarn
yarn add @lzwme/asmd-calc
# pnpm
pnpm add @lzwme/asmd-calc

Useage

1. Calculation example using simple tool method

es module

import { add } from '@lzwme/asmd-calc';

console.log(add(0.1, 0.2, 0.3));
// => 0.6

commonjs

const calc = require('@lzwme/asmd-calc');

console.log(calc.add(0.1, 0.2, 0.3));
// => 0.6

2. Calculation example using chain operation

es module

import { AsmdCalc } from '@lzwme/asmd-calc';

const a = new AsmdCalc(0);
console.log(+a.add(0.1).add(0.2, 0.3));
// => 0.6

const b = new AsmdCalc(0.3);
  b.add(0.1, 0.2)
    .add(0.1)
    .sub(0.1, 0.2)
    .sub(0.1)
    .div(0.3)
    .mul(0.3);
console.log(+b);
// => 0.3
console.log(b.value);
// => 0.3

commonjs

const AsmdCalc = require('@lzwme/asmd-calc').AsmdCalc;

const calc = new AsmdCalc(0);
console.log(calc.add(0.1).add(0.2, 0.3));
// => 0.6

API

  • add(...args); - Addition
  • sub(...args); - Subtraction
  • mul(...args); - Multiplication
  • div(...args); - Division
  • keepDotLength(value, len, isRounding = false): number; - Keep N decimal places
  • toFixed(value, len): string; - Similar to Number.prototype.toFixed, but fixed precision of the result
  • getDecimalLen(num): number; - Get the decimal length
  • toNonExponential(num): string; - Convert to string format of unscientific counting method

Development and testing

  • Development
pnpm install
pnpm start
  • Testing
npm test
npm run benchmark
  • Build
npm run build

Benchmark

npm run benchmark

See:Benchmark

The following results are the time-consuming comparison of executing 10000 * N times on the same machine:

| type/times | jsRaw | asmd-calc | mathjs | | --- | --- | --- | --- | | add-10000 | 19.225ms | 169.535ms | 415.145ms | | sub-10000 | 16.269ms | 34.827ms | 171.263ms | | mul-10000 | 18.518ms | 51.625ms | 235.868ms | | div-10000 | 27.025ms | 79.504ms | 300.706ms |

Pre execution of 1000000 times and then stats time-consuming of execution of 10000 * N times:

| type/times | jsRaw | asmd-calc | mathjs | | --- | --- | --- | --- | | add-10000 | 7.768ms | 155.836ms | 362.819ms | | sub-10000 | 8.339ms | 25.147ms | 155.611ms | | mul-10000 | 9.995ms | 35.685ms | 224.357ms | | div-10000 | 15.666ms | 77.407ms | 280.322ms |

References

License

@lzwme/asmd-calc is released under the MIT license.

该插件由志文工作室开发和维护。