#intparts
Manipulate the integer parts of a JS Number, including frexp
and ldexp
.
##Author(s) Christoph Zurnieden [email protected]
##Installation
$ git clone https://github.com/czurnieden/intparts.git
$ cd intparts
$ npm install -g
There is also a Unix (or newer Macs) dependent CLI version in ./bin
.
Please be aware that this module assumes little endian.
##Version
0.0.1 Initial publication
##Description
This library implements some of the functions to inspect the innards of a 64 bit double
, the default type in ECMAScript up to version 5.1 at least. It allows direct manipulation of the bits in a Number
. Included are ports of C-lib's frexp
and ldexp
.
This module runs as ams.js where applicable.
##Usage
The usage is like with any other node/browser module:
var ip = require('intparts');
var raw_exponent = ip.getexponent(123.312); // 0x405
var unbiased_exponent = ip.frexp(123.321)[1]; // 7
This program offers ten functions which are in alphabetical order:
frexp(number)
-
Return: an
Uint32Array
containing the mantissa and the exponent in that order such thatmantissa * 2^exponent = number
getexponent(number)
- Return: the biased, raw exponent in hexadecimal representation
gethigh(number)
- Return: the high word in hexadecimal representation
getlow(number)
- Return: the low word in hexadecimal representation
getsign(number)
- Return: the sign bit in hexadecimal representation
getwords(number)
- Return: the comma separated low and high words in hexadecimal representation and in that order
ldexp(mantissa,exponent)
-
Return: a number such that
mantissa * 2^exponent = number
sethigh(integer,number)
-
Sets the high word of
number
Return: the manipulated number
setlow(integer,number)
-
Sets the high word of
number
Return: the manipulated number
setwords(number,high_integer,low_integer)
-
Sets the words of
number
Return: the manipulated number
This module does no error catching.
##Example
No example yet, but ideas are welcome.