Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of 32-bit floats or 64-bit longs in JavaScript?

Does anyone know of a JavaScript library that accurately implements the IEEE 754 specification for 32-bit floating-point values? I'm asking because I'm trying to write a cross-compiler in JavaScript, and since the source language has strict requirements that floating-point values adhere to IEEE 754, the generated JavaScript code must do so as well. This means that I must be able to get exactly the correct IEEE 754 values for addition, subtraction, multiplication, and division of 32-bit floats. Unfortunately, the standard JavaScript Number type is a 64-bit double, which will give different results than what I'm expecting. The project really does have to be in JavaScript, and this is the only major stumbling block I have yet to get past.

I'm also running into this problem with 64-bit longs.

like image 250
templatetypedef Avatar asked Jan 26 '11 06:01

templatetypedef


People also ask

Does JavaScript support 64-bit?

JavaScript Numbers are Always 64-bit Floating Point Unlike many other programming languages, JavaScript does not define different types of numbers, like integers, short, long, floating-point etc.

Does JavaScript support int64?

JavaScript represents numbers using IEEE-754 double-precision (64 bit) format.

Are floats 32 or 64-bit?

Floats generally come in two flavours: “single” and “double” precision. Single precision floats are 32-bits in length while “doubles” are 64-bits. Due to the finite size of floats, they cannot represent all of the real numbers - there are limitations on both their precision and range.

Is JavaScript a 32-bit?

JavaScript Uses 32 bits Bitwise Operands JavaScript stores numbers as 64 bits floating point numbers, but all bitwise operations are performed on 32 bits binary numbers.


1 Answers

The Closure library has a 64-bit long implementation, at least.

like image 105
gsnedders Avatar answered Oct 01 '22 19:10

gsnedders