确定一个数字可以浮法精确代表/双格式 [英] Determine if a number can be precisely represented in float/double format

查看:171
本文介绍了确定一个数字可以浮法精确代表/双格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定一个数,例如1.577,可以精确地在浮动或双格式表示?

How to determine if a number, for example 1.577, can be precisely represented in float or double format?

这意味着它是真实的1.577不是1.566999999999994324等

It means it is real 1.577 not a 1.566999999999994324 etc.

编辑:
我寻找一种工具,在那里我可以输入一个数字,它会显示它的双/浮点表示。因此,这不仅是C#的相关问题。

I'm looking for a tool, where I can type a number and it will display double/float representation of it. So it's not only c# related question.

推荐答案

您可以使用的在线十进制浮点转换。例如,在1.577的类型,你会得到两个指示,这是不准确:

You can use an online decimal to floating-point converter. For example, type in 1.577 and you get two indications that it is not exact:

1)不精确复选框被选中

1) The "Inexact" box is checked

2)转换为1.5769999999999999573674358543939888477325439453125在双精度浮点

2) It converts to 1.5769999999999999573674358543939888477325439453125 in double precision floating-point.

对比度,为若干像1.25,打印为1.25,而不精确框未选中。

Contrast that to a number like 1.25, which prints as 1.25, and the "Inexact" box is NOT checked.

(该转换器还可以检查单精度的数字。)

(That converter can also check single-precision numbers.)

这篇关于确定一个数字可以浮法精确代表/双格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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