Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
kawanet committed Dec 14, 2024
1 parent a7a070c commit e692aa8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
[![Node.js CI](https://github.com/kawanet/int64-buffer/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/kawanet/int64-buffer/actions/)
[![Coverage Status](https://coveralls.io/repos/github/kawanet/int64-buffer/badge.svg?branch=master)](https://coveralls.io/github/kawanet/int64-buffer?branch=master)

JavaScript's number based on IEEE-754 could only handle [53 bits](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) precision.
This module provides two pair of classes: `Int64BE`/`Uint64BE` and `Int64LE`/`Uint64LE` which could hold 64 bits long integer and loose no bit.
JavaScript's number type, based on IEEE-754, can only handle [53 bits](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) of precision.
This module provides two pairs of classes: `Int64BE`/`Uint64BE` and `Int64LE`/`Uint64LE`, which can hold 64-bit long integers without losing any bits.

### Features

- `Int64BE`/`Int64LE` for signed integer, `Uint64BE`/`Uint64LE` for unsigned.
- `Int64BE`/`Int64LE` for signed integers, `Uint64BE`/`Uint64LE` for unsigned integers.
- `Int64BE`/`Uint64BE` for big-endian, `Int64LE`/`Uint64LE` for little-endian.
- `Buffer`/`Uint8Array`/`Array`/`Array`-like storage of 8 bytes length with offset.
- No mathematical methods provided, such as `add()`, `sub()`, `mul()`, `div()` etc.
- Optimized only for 64 bits. If you need Int128, use [bignum](https://www.npmjs.com/package/bignum) etc.
- Small. 3KB when minified. No other module required. Portable pure JavaScript.
- [Tested](https://github.com/kawanet/int64-buffer/actions/) on node.js v10, v12, v14 and Web browsers.
- No mathematical methods provided, such as `add()`, `sub()`, `mul()`, `div()`, etc.
- Optimized only for 64 bits. If you need Int128, use [bignum](https://www.npmjs.com/package/bignum) or similar libraries.
- Small. 3KB when minified. No other modules required. Portable pure JavaScript.
- [Tested](https://github.com/kawanet/int64-buffer/actions/) on node.js v18, v20, v22 and Web browsers.

### Usage

`Int64BE` is the class to host a 64 bit signed long integer `int64_t`.
`Int64BE` is the class to host a 64-bit signed long integer `int64_t`.

```js
const {Int64BE} = require("int64-buffer");
import {Int64BE} from "int64-buffer";

const big = new Int64BE(-1);

Expand All @@ -35,10 +35,10 @@ console.log(big.toBuffer()); // <Buffer ff ff ff ff ff ff ff ff>

It uses `Buffer` on Node.js and `Uint8Array` on modern Web browsers.

`Uint64BE` is the class to host a 64 bit unsigned positive long integer `uint64_t`.
`Uint64BE` is the class to host a 64-bit unsigned positive long integer `uint64_t`.

```js
const {Uint64BE} = require("int64-buffer");
import {Uint64BE} from "int64-buffer";

const big = new Uint64BE(Math.pow(2, 63)); // a big number with 64 bits

Expand All @@ -47,7 +47,7 @@ console.log(big - 0); // 9223372036854776000 = IEEE-754 loses last bits
console.log(big + ""); // "9223372036854775808" = perfectly correct
```

`Int64LE` and `Uint64LE` work as same as above but with little-endian storage.
`Int64LE` and `Uint64LE` work the same way as above but with little-endian storage.

### Input Constructor

Expand Down

0 comments on commit e692aa8

Please sign in to comment.