Javascript中的单精度浮点仿真(float32) [英] Single precision float emulation in Javascript (float32)

查看:732
本文介绍了Javascript中的单精度浮点仿真(float32)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以某种方式模拟Javascript中的单精度浮点数?根据Doug Crockford的博客Number is 64-bit floating point,但是我必须使用单一来移植C ++算法来计算单精度浮点数的误差。

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.

推荐答案

ES6标准有Math.fround(),它将float64转换为float32然后再返回,有效地将float舍入为float32精度。有关详细信息,请参见本文

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.

这篇关于Javascript中的单精度浮点仿真(float32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆