Search code examples
javascriptfloating-pointlong-integerieee-754

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.


Solution

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