我正在编写一个程序,该程序要求我迭代 [1,2) 范围内的所有单精度浮点(23 个小数位)数字。我不太确定该怎么做。我正在用 C# 编写这个程序。
如果有人能给我一些帮助,那就太好了。谢谢!
最佳答案
您可以使用BitConverter
用于将 float
值转换为 int
并返回的静态类。因此您可以访问它的位。
int one = BitConverter.ToInt32(BitConverter.GetBytes(1f), 0);
int two = BitConverter.ToInt32(BitConverter.GetBytes(2f), 0);
for (int i = one; i < two; i++)
{
float f = BitConverter.ToSingle(BitConverter.GetBytes(i), 0);
// Your stuff
}
关于c# - 迭代 [1,2) 之间的单精度 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32683812/