简体   繁体   English

最小正 float64 值

[英]Minimum positive float64 value

Just like This question , I need to a positive number that is as close to zero as possible, without it being zero, but in Go.就像这个问题一样,我需要一个尽可能接近零的正数,而不是零,但在 Go 中。

The math package has a constant for this and similar values, just use that: math.SmallestNonzeroFloat64 : math package 对于这个值和类似值有一个常量,只需使用那个: 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)
)

Printing its value:打印它的值:

fmt.Println(math.SmallestNonzeroFloat64)

Outputs (try it on the Go Playground ):输出(在Go 游乐场上尝试):

5e-324

(Note: it's greater than the constant due to rounding in the fmt package.) (注意:由于fmt package 中的四舍五入,它大于常量。)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM