
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
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 this library with
$ npm install float80
>>> 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.
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");
}
}
The weird 48-bit float parsing is available in Float48
class.
Same API as Float80
.
MIT
FAQs
Read 80-bit Extended Floating Point Numbers from buffers
The npm package float80 receives a total of 530 weekly downloads. As such, float80 popularity was classified as not popular.
We found that float80 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.