简体   繁体   English

将位打印为 IEEE-754 浮点数

[英]Printing bits as IEEE-754 float

Is there some clever and reliable way to print series of bits as an IEEE-754 without actually using a float type?是否有一些巧妙而可靠的方法可以在不实际使用浮点类型的情况下将一系列位打印为 IEEE-754?

I have found a way to print fractions, which allows me to represent the float as aa fraction.我找到了一种打印分数的方法,它允许我将浮点数表示为一个分数。 However, I then came to realize that the exponent may range from -127 to 128 (after adjusting with bias), which may result in the multiplication mantissa * 2^128 .然而,我后来意识到指数可能在 -127 到 128 之间(在调整偏差后),这可能导致乘法mantissa * 2^128 The fraction method relies on representing the numerator as an integer, and I would require a really large integer to do this multiplication.分数法依赖于将分子表示为 integer,我需要一个非常大的 integer 来执行此乘法。 I mean, I could use "custom" type to represent this large value (ie https://gmplib.org/ ), but I would prefer if to avoid this.我的意思是,我可以使用“自定义”类型来表示这个大值(即https://gmplib.org/ ),但我更愿意避免这种情况。 If we multiplied by 10^x, I could simply adjust the decimal point and add some zeros, but sadly that's not the case either.如果我们乘以 10^x,我可以简单地调整小数点并添加一些零,但遗憾的是,情况也不是这样。

I have not been able to find anything that mentions any solution for this.我一直找不到任何提到任何解决方案的内容。 Probably due to the fact that googling stuff like "print from可能是因为谷歌搜索诸如“打印自

Why am I actually trying to do this?为什么我实际上要这样做?
I'm only doing this to get a better understanding of how floats (IEEE-754 in particular) work, and I find that it always help to do some practical example.我这样做只是为了更好地理解浮点数(尤其是 IEEE-754)是如何工作的,我发现做一些实际的例子总是有帮助的。 So I thought "Hey, why not try to code it?".所以我想“嘿,为什么不尝试编码呢?”。 This has no practical application (that I know of)!没有实际应用(据我所知)!

So, almost immediately after posting this, I finally succeded in finding the resources I've been looking for.所以,几乎是在发布这篇文章之后,我终于成功地找到了我一直在寻找的资源。

https://www.ryanjuckett.com/printing-floating-point-numbers/ talks about it, and references other relevant sources.https://www.ryanjuckett.com/printing-floating-point-numbers/ 对此进行了讨论,并参考了其他相关资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测非 IEEE-754 浮点数,以及如何使用它们? - How to detect non IEEE-754 float, and how to use them? IEEE-754的浮点数,双精度数和四进制数是否保证精确表示-2,-1,-0、0、1、2? - Does IEEE-754 float, double and quad guarantee exact representation of -2, -1, -0, 0, 1, 2? 如何输出IEEE-754格式的整数作为浮点数 - How to output IEEE-754 format integer as a float 如何将float转换为double(都存储在IEEE-754表示中)而不会丢失精度? - How to convert float to double(both stored in IEEE-754 representation) without losing precision? 检查符号位的位置是否足以确定 IEEE-754 浮点数相对于 integer 字节序的字节序? - Is checking the location of the sign bit enough to determine endianness of IEEE-754 float with respect to integer endianness? 将 2 uint16_t 转换为 32-float IEEE-754 格式 - Converting 2 uint16_t to 32-float IEEE-754 fomat 32位,64位和80位浮点IEEE-754的可表示值范围? - Range of representable values of 32-bit, 64-bit and 80-bit float IEEE-754? 在C ++中编写符合IEEE-754标准的双/浮点分区的最快方法是什么? - What is the fastest way to write a IEEE-754 compliant double/float division in C++? IEEE 754浮点数的有效数字 - significant digits with IEEE 754 float 添加 IEEE-754 格式的正数和负数 - Adding positive and negative numbers in IEEE-754 format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM