Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justjavac/deno_ieee754
Parse IEEE754 floating point numbers for Deno
https://github.com/justjavac/deno_ieee754
deno deno-mod deno-module deno-modules denomod ieee ieee754 math
Last synced: 12 days ago
JSON representation
Parse IEEE754 floating point numbers for Deno
- Host: GitHub
- URL: https://github.com/justjavac/deno_ieee754
- Owner: justjavac
- License: mit
- Created: 2020-08-07T01:48:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-03T13:49:51.000Z (over 2 years ago)
- Last Synced: 2024-11-22T17:05:29.656Z (30 days ago)
- Topics: deno, deno-mod, deno-module, deno-modules, denomod, ieee, ieee754, math
- Language: TypeScript
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deno_ieee754
[![tag](https://img.shields.io/github/release/justjavac/deno_ieee754)](https://github.com/justjavac/deno_ieee754/releases)
[![ci](https://github.com/justjavac/deno_ieee754/actions/workflows/ci.yml/badge.svg)](https://github.com/justjavac/deno_ieee754/actions/workflows/ci.yml)
[![license](https://img.shields.io/github/license/justjavac/deno_ieee754)](https://github.com/justjavac/deno_ieee754/blob/master/LICENSE)Parse IEEE754 floating point numbers for Deno.
## Usage
```ts
import * as ieee754 from "https://deno.land/x/ieee754/mod.ts";
// or
// import read from "https://deno.land/x/ieee754/read.ts";
// import write from "https://deno.land/x/ieee754/write.ts";const buf: Uint8Array = Uint8Array.of(0x42, 0x29, 0xae, 0x14);
const f64 = ieee754.read(buf, 0, false, 52, 8);
console.log(f64); // 42.42const EPSILON = 0.00001;
const f32 = ieee754.read(buf, 0, false, 23, 4);
console.log(Math.abs(f32 - 42.42) < EPSILON); // true
```Use with number array:
```ts
const arr: number[] = [1, 2, 3]; // a number array
const buf = Uint8Array.from(arr); // convert to `Uint8Array`
const num = ieee754.read(buf, 0, false, 23, 4);
```## APIs
**read**:
```ts
/**
* Read IEEE754 floating point numbers from a array.
* @param buffer the buffer
* @param offset offset into the buffer
* @param isLE is little endian?
* @param mLen mantissa length
* @param nBytes number of bytes
*/
function read(
buffer: Uint8Array,
offset: number,
isLE: boolean,
mLen: number,
nBytes: number,
): number;
```**write**:
```ts
/**
* Write IEEE754 floating point numbers to a array.
* @param buffer the buffer
* @param value value to set
* @param offset offset into the buffer
* @param isLE is little endian?
* @param mLen mantissa length
* @param nBytes number of bytes
*/
function write(
buffer: Uint8Array,
value: number,
offset: number,
isLE: boolean,
mLen: number,
nBytes: number,
): void;
```### License
[deno_ieee754](https://github.com/justjavac/deno_ieee754) is released under the
MIT License. See the bundled [LICENSE](./LICENSE) file for details.