在MongoDB中将$ inc与浮点值一起使用时是否有陷阱? [英] Are there any gotchas when using $inc with float values in MongoDB?

查看:452
本文介绍了在MongoDB中将$ inc与浮点值一起使用时是否有陷阱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,是否完全支持以浮点值递增?

Firstly, is it fully supported to increment by floating values?

保持什么水平的浮点精度?

What level of floating-point precision is maintained?

推荐答案

MongoDB确实支持按浮点值递增.如果当前为其他某种数字类型,则将导致存储的值转换为浮点数;如果先前的值是非常大的64位整数,则可能导致舍入错误.

MongoDB does support incrementing by floating point values. This will cause the stored value to be converted to floating point if it is currently some other numeric type, which can lead to rounding errors if the previous value was a very large 64-bit integer.

所有涉及浮点数的标准警告均适用.与Web浏览器中的JavaScript解释器一样,MongoDB存储IEEE双精度(64位)浮点值.这些值的精度为53位.中间计算 可以使用80位长双精度数来计算,但最终结果始终存储为64位双精度浮点值.

All of the standard caveats involving floating point numbers apply. MongoDB, like JavaScript interpreters in web browsers, stores IEEE double precision (64-bit) floating point values. These values have 53 bits of precision. Intermediate calculations may be computed using 80-bit long doubles, but the final result is always stored as a 64-bit double precision floating point value.

这篇关于在MongoDB中将$ inc与浮点值一起使用时是否有陷阱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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