Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single precision float emulation in Javascript (float32)

Is it possible to somehow emulate single precision float in Javascript? According to Doug Crockford's blog "Number is 64-bit floating point", but I have to use single one for porting C++ algorithm which calculates single precision float's error.

like image 818
qqryq Avatar asked Oct 31 '10 09:10

qqryq


1 Answers

The ES6 standard has Math.fround() which converts a float64 to float32 and then back again, effectively rounding the float to float32 precision. See this article for details.

like image 103
SteveH Avatar answered Sep 20 '22 21:09

SteveH