Socket
Book a DemoInstallSign in
Socket

float80

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

float80

Read 80-bit Extended Floating Point Numbers from buffers

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
524
-7.75%
Maintainers
1
Weekly downloads
 
Created
Source

float80

Read 80-bit Extended Floating Point Numbers from buffers

It turns out that there does not appear to be any way to read the extended precision floating point format in Javascript, aka "long doubles".

Until now, anyway.

Get it

Get this library with

$ npm install float80

Usage

>>> const {Float80} = require('float80')

>>> f = Float80.fromBytes([0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

>>> f.toString()
1

>>> f.asNumber()
<BigNumber: [String: 1]>

The number parsed by Float80 is stored in a BigNumber instance, and exposed by the asNumber function.

Generating 80 bit floats

Here is a trivial C program that you can use to view how 80-bit floats are represented:

#include <stdio.h>

union {
  long double value;
  unsigned char bytes[10];
} dc;

int main(int argc, char ** argv) {
  int i;
  while(1) {
      printf("Enter long double: ");
      scanf("%Lf", &dc.value);
      for (i = 0; i < 10; ++i) {
         printf("%02x ", dc.bytes[9 - i]);
      }
      printf("\n");
  }
}

Bonus: 48-bit floats.

The weird 48-bit float parsing is available in Float48 class.

Same API as Float80.

License

MIT

FAQs

Package last updated on 30 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.