最小正 float64 值
Minimum positive float64 value
就像一样,我需要一个尽可能接近零的正数,而不是零,但在围棋中。
math
package has a constant for this and similar values, just use that: math.SmallestNonzeroFloat64
:
const (
MaxFloat32 = 3.40282346638528859811704183484516925440e+38 // 2**127 * (2**24 - 1) / 2**23
SmallestNonzeroFloat32 = 1.401298464324817070923729583289916131280e-45 // 1 / 2**(127 - 1 + 23)
MaxFloat64 = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52
SmallestNonzeroFloat64 = 4.940656458412465441765687928682213723651e-324 // 1 / 2**(1023 - 1 + 52)
)
正在打印其值:
fmt.Println(math.SmallestNonzeroFloat64)
输出(在 Go Playground 上尝试):
5e-324
(注意:由于 fmt
包中的四舍五入,它大于常量。)
就像
math
package has a constant for this and similar values, just use that: math.SmallestNonzeroFloat64
:
const (
MaxFloat32 = 3.40282346638528859811704183484516925440e+38 // 2**127 * (2**24 - 1) / 2**23
SmallestNonzeroFloat32 = 1.401298464324817070923729583289916131280e-45 // 1 / 2**(127 - 1 + 23)
MaxFloat64 = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52
SmallestNonzeroFloat64 = 4.940656458412465441765687928682213723651e-324 // 1 / 2**(1023 - 1 + 52)
)
正在打印其值:
fmt.Println(math.SmallestNonzeroFloat64)
输出(在 Go Playground 上尝试):
5e-324
(注意:由于 fmt
包中的四舍五入,它大于常量。)