gpt4 book ai didi

go - '%b'动词是 float 时输出什么

转载 作者:行者123 更新时间:2023-12-01 23:16:22 24 4
gpt4 key购买 nike

根据 go 文档,%b used with floating number 意味着:

decimalless scientific notation with exponent a power of two,in the manner of strconv.FormatFloat with the 'b' format,e.g. -123456p-78

如下代码所示,程序输出为

8444249301319680p-51

我对 float 中的 %b 有点困惑,谁能告诉我这个结果是如何计算出来的?另外,p- 是什么意思?

f := 3.75
fmt.Printf("%b\n", f)
fmt.Println(strconv.FormatFloat(f, 'b', -1, 64))

最佳答案

指数为 2 的幂的无小数科学计数法 表示如下:

8444249301319680*(2^-51) = 3.75 or 8444249301319680/(2^51) = 3.75

p-51 表示 2^-51 也可以计算为 1/(2^51)

关于浮点运算的好文章。 https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

关于go - '%b'动词是 float 时输出什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68769014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com