golang: what does “%b” do in fmt.Printf for float64 and what is Min subnormal positive double in float64 in binary format?

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

golang doc for Package fmt Floating-point and complex constituents says:

Floating-point and complex constituents:
%b decimalless scientific notation with exponent a power of two, in the manner of strconv.FormatFloat with the 'b' format, e.g. -123456p-78

and my test:

fmt.Printf("%b\n", 1.0) 

the result:
4503599627370496p-52
what is it? your guess is mine!
so test this:

fmt.Printf("0b%b\n", 255) //0b11111111

it is ok. so i think this is interesting and informative to share.

回答1:

then i did some Research and after many hours of research with IEEE 754 binary representation; many inserting results came up:
good point to start is:

https://en.wikipedia.org/wiki/Double-precision_floating-point_format https://en.wikipedia.org/wiki/IEEE_floating_point

then some test and results:

}

conclusion:
%b for float shows only significand, done.
this single line took many hours of my time!
any comments are welcome, thanks.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!