GithubHelp home page GithubHelp logo

justjavac / deno_ieee754 Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 23 KB

Parse IEEE754 floating point numbers for Deno

License: MIT License

TypeScript 100.00%
deno deno-mod deno-modules denomod deno-module ieee ieee754 math

deno_ieee754's Introduction

deno_ieee754

tag ci license

Parse IEEE754 floating point numbers for Deno.

Usage

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.42

const 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:

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:

/**
 * 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:

/**
 * 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 is released under the MIT License. See the bundled LICENSE file for details.

deno_ieee754's People

Contributors

justjavac avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.