Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@phensley/decimal
Advanced tools
Arbitrary precision decimal math, used to support @phensley/cldr, but can be used by itself.
NPM:
npm install --save @phensley/decimal
Yarn:
yarn add @phensley/decimal
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
[1.2.10]
FAQs
Arbitrary precision decimal math
The npm package @phensley/decimal receives a total of 545 weekly downloads. As such, @phensley/decimal popularity was classified as not popular.
We found that @phensley/decimal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.