如何查看传入的浮点数的大小? [英] How to see the size of the incoming floating point number?

查看:90
本文介绍了如何查看传入的浮点数的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户将数字写到输入中,并存储在字符串中。如何检查此数字是否包含在 float 类型的大小中,还是需要 double ? p>

The user writes a number to the input, it is stored in a string. How can I check if this number is included in size in the float type or does it need a double?

推荐答案

除非您的浮点数很大或非常小,即超出-3.4E38到3.4E38的范围,则浮点数32将存储您扔给它的所有内容,但不包括大小。因此,真正的问题是您需要多少个有效数字以最小化舍入误差。我建议您阅读 https://www.itu.dk/~sestoft/bachelor /IEEE754_article.pdf

Unless your floating point numbers are huge or extremely small, i.e. out of the range spanning -3.4E38 to 3.4E38, a float 32 will store anything you throw at it in terms of size but not accuracy. As such, the real issue is how many significant digits you need in order to minimize rounding errors. I recommend you to read https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf

如果不受磁盘空间或内存的限制,则只需使用float 64。

If you are not limited by disk space or memory, then just go for float 64.

这篇关于如何查看传入的浮点数的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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