开发者社区> 镜像站> NPM> double-utils
double-utils
Utilities for decomposing doubles (Number) and pretty printing
Last updated a year ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install double-utils 
SYNC missed versions from official npm registry.

double-utils

Utilities for decomposing doubles (Number) and pretty printing

Usage

var doubleUtils = require('double-utils')

console.log(doubleUtils.sign(Math.PI))
console.log(doubleUtils.exp(Math.PI))
console.log(doubleUtils.frac(Math.PI))

// OR
console.log(doubleUtils.decompose(Math.PI))

console.log(doubleUtils.format(Math.PI))

API

const n = doubleUtils.sign(double)

Returns the sign bit. 0 is positive, 1 is negative

const exp = doubleUtils.exp(double)

Returns the exponent part, which is a number between [0, 2048)

const frac = doubleUtils.frac(double)

Returns the fractional (or mantissa) part, which is a 52-bit number

const [sign, exp, frac] = doubleUtils.decompose(double)

Run the above three methods at once

const str = doubleUtils.format(double, guide = true)

Print the number as a bit string, with an optional guide.

Install

npm install double-utils

License

ISC

Current Tags

  • 1.0.0                                ...           latest (a year ago)

1 Versions

  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None