aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-04-30 17:23:35 -0700
committerRobert Griesemer <gri@golang.org>2021-05-03 16:23:09 +0000
commit7b768d43d0f0e3e734369496bb1caa409d4bd0bb (patch)
tree035a54d8cc1481b8fc7ff3e1045fa3aa07eff088 /src/math
parentbe1da9cdeecba15d0f68b4dcc145bcc77c0c4ace (diff)
downloadgo-7b768d43d0f0e3e734369496bb1caa409d4bd0bb.tar.gz
go-7b768d43d0f0e3e734369496bb1caa409d4bd0bb.zip
math: replace float32/64 extrema with exact expressions
Follow-up on https://golang.org/cl/315170. Updates #44057. Updates #44058. Change-Id: I0b071e8ee7a1c97aae2436945cc9583cde3b40b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/315969 Trust: Robert Griesemer <gri@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/math')
-rw-r--r--src/math/const.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/math/const.go b/src/math/const.go
index 441b295ed4..31954b0cae 100644
--- a/src/math/const.go
+++ b/src/math/const.go
@@ -28,11 +28,11 @@ const (
// Max is the largest finite value representable by the type.
// SmallestNonzero is the smallest positive, non-zero value representable by the type.
const (
- MaxFloat32 = 3.40282346638528859811704183484516925440e+38 // 2**127 * (2**24 - 1) / 2**23
- SmallestNonzeroFloat32 = 1.401298464324817070923729583289916131280e-45 // 1 / 2**(127 - 1 + 23)
+ MaxFloat32 = 0x1p127 * (1 + (1 - 0x1p-23)) // 3.40282346638528859811704183484516925440e+38
+ SmallestNonzeroFloat32 = 0x1p-126 * 0x1p-23 // 1.401298464324817070923729583289916131280e-45
- MaxFloat64 = 1.79769313486231570814527423731704356798070e+308 // 2**1023 * (2**53 - 1) / 2**52
- SmallestNonzeroFloat64 = 4.9406564584124654417656879286822137236505980e-324 // 1 / 2**(1023 - 1 + 52)
+ MaxFloat64 = 0x1p1023 * (1 + (1 - 0x1p-52)) // 1.79769313486231570814527423731704356798070e+308
+ SmallestNonzeroFloat64 = 0x1p-1022 * 0x1p-52 // 4.9406564584124654417656879286822137236505980e-324
)
// Integer limit values.