Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@phensley/decimal

Package Overview
Dependencies
Maintainers
1
Versions
198
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phensley/decimal - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

18

package.json
{
"name": "@phensley/decimal",
"version": "1.0.7",
"version": "1.0.8",
"description": "Arbitrary precision decimal math",

@@ -39,17 +39,17 @@ "main": "lib/index.js",

"dependencies": {
"tslib": "1.11.1"
"tslib": "^1.11.1"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.7.8",
"@types/jest": "25.1.3",
"@types/node": "^10.14.10",
"@types/jest": "^25.1.3",
"@types/node": "^13.9.2",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.4",
"chalk": "^2.3.2",
"jest": "25.1.0",
"jest": "^25.1.0",
"rimraf": "^3.0.0",
"ts-jest": "25.2.1",
"tslint": "^5.18.0",
"ts-jest": "^25.2.1",
"tslint": "^6.1.0",
"tslint-no-circular-imports": "^0.7.0",
"typescript": "3.8.x"
"typescript": "^3.8.x"
},

@@ -69,3 +69,3 @@ "jest": {

},
"gitHead": "f411d4925d2d57589ef2cd9f1c13ef6871224bc3"
"gitHead": "42451ff35e9b5e3abeb04d2fd71ae0fc0639a82a"
}

@@ -1,3 +0,95 @@

[`@phensley/decimal`](https://www.npmjs.com/package/@phensley/decimal) ![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/decimal)
# @phensley/decimal
Arbitrary precision decimal math, used to support @phensley/cldr, but can be used standalone.
[![@phensley/decimal](https://badge.fury.io/js/%40phensley%2Fdecimal.svg)](https://www.npmjs.com/package/@phensley/decimal) [![min+gzip](https://badgen.net/bundlephobia/minzip/@phensley/decimal)](https://bundlephobia.com/result?p=@phensley/decimal)
Arbitrary precision decimal math, used to support [@phensley/cldr](https://www.npmjs.com/package/@phensley/clde), but can be used by itself.
## Installation
NPM:
```
npm install --save @phensley/decimal
```
Yarn:
```
yarn add @phensley/decimal
```
## Example
```typescript
import { Decimal, DecimalConstants, MathContext } from '@phensley/decimal';
const area = (radius: Decimal, ctx: MathContext) =>
DecimalConstants.PI.multiply(radius, ctx).multiply(radius, ctx);
const calc = (ctx: MathContext) => {
for (const r of ['.002', '1', '1.5', '999.999']) {
const radius = new Decimal(r);
console.log(
`area of circle with radius ${r.padEnd(7)} is ${area(radius, ctx)}`
);
}
console.log();
};
for (const scale of [5, 15]) {
console.log(`Scale ${scale}:`);
calc({ scale });
}
for (const precision of [10, 30]) {
console.log(`Precision ${precision}:`);
calc({ precision });
}
const LIGHT_YEAR_KM = new Decimal('9.461e12');
const NEAREST_STARS: any = {
'Proxima Centauri': '4.32',
"Barnard's Star": '5.96',
'Wolf 359': '7.78',
'Lalande 21185': '8.29'
};
for (const name of Object.keys(NEAREST_STARS)) {
const distly = NEAREST_STARS[name];
const distkm = new Decimal(distly).multiply(LIGHT_YEAR_KM, { precision: 30 });
console.log(
`Distance to ${name.padEnd(16)} is ${distkm.toString()} kilometers`
);
}
```
```
Scale 5:
area of circle with radius .002 is 0.00001
area of circle with radius 1 is 3.14159
area of circle with radius 1.5 is 7.06858
area of circle with radius 999.999 is 3141586.36841
Scale 15:
area of circle with radius .002 is 0.000012566370614
area of circle with radius 1 is 3.141592653589793
area of circle with radius 1.5 is 7.068583470577035
area of circle with radius 999.999 is 3141586.370407627651860
Precision 10:
area of circle with radius .002 is 0.00001256637061
area of circle with radius 1 is 3.141592654
area of circle with radius 1.5 is 7.068583470
area of circle with radius 999.999 is 3141586.370
Precision 30:
area of circle with radius .002 is 0.0000125663706143591729538505735331
area of circle with radius 1 is 3.14159265358979323846264338328
area of circle with radius 1.5 is 7.06858347057703478654094761238
area of circle with radius 999.999 is 3141586.37040762765152975625124
Distance to Proxima Centauri is 40871520000000 kilometers
Distance to Barnard's Star is 56387560000000 kilometers
Distance to Wolf 359 is 73606580000000 kilometers
Distance to Lalande 21185 is 78431690000000 kilometers
```
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