确定一个浮点数是不是一个分数的非理性 [英] Determine if a float number is irrational of a fraction
问题描述
谢谢! p>
所有浮点数数字是合理的,因为尾数具有固定长度。如果你有一个你需要匹配的特定的数字列表,你可以比较随机数与数字上的数字。以设定的浮点精度列出,但请记住,由于截断或四舍五入,您将获得误报。
I have a random float number and I have to determine if it is an irrational number like √2 or a fraction like 123/321. Both of them are represented like an endless set of numbers anywhere but is there any way to definitely say whether a number is a fraction or it's irrational?
Thank you!
All floating point numbers are rational because the mantissa has a fixed length. Irrational numbers stored in floating point are truncated into rational numbers.
If you have a specific list of numbers you need to match, you can compare the random number to numbers on the list at a set floating point precision, but do keep in mind that you will get false positives due to truncation or rounding.
这篇关于确定一个浮点数是不是一个分数的非理性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!