Skip to content

Commit a1038f7

Browse files
committed
pkg/math: fix Log2E and Log10E constant expressions
They were a division of integer constants, which got truncated, meaning that Log2E rounded down to 1 and Log10E to 0. To force them to be floating-point constants, like the CUE ones, turn the dividend into a floating-point constant. I found this problem since staticcheck correctly pointed out a constant integer division which resulted in zero: math.go:156:11: the integer division '100… / 230…' results in zero (SA4025) Signed-off-by: Daniel Martí <[email protected]> Change-Id: I36ee54a7c8aff06368016b855536a9614dbbf229 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/557322 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 63a4256 commit a1038f7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/math/math.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ const (
151151
SqrtPhi = 1.27201964951406896425242246173749149171560804184009624861664038 // https://oeis.org/A139339
152152

153153
Ln2 = 0.693147180559945309417232121458176568075500134360255254120680009 // https://oeis.org/A002162
154-
Log2E = 1000000000000000000000000000000000000000000000000000000000000000 / 693147180559945309417232121458176568075500134360255254120680009
154+
Log2E = 1000000000000000000000000000000000000000000000000000000000000000.0 / 693147180559945309417232121458176568075500134360255254120680009
155155
Ln10 = 2.30258509299404568401799145468436420760110148862877297603332790 // https://oeis.org/A002392
156-
Log10E = 10000000000000000000000000000000000000000000000000000000000000 / 23025850929940456840179914546843642076011014886287729760333279
156+
Log10E = 10000000000000000000000000000000000000000000000000000000000000.0 / 23025850929940456840179914546843642076011014886287729760333279
157157
)
158158

159159
// Copysign returns a value with the magnitude

pkg/math/math_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Example_constants() {
5454
// SqrtPi: 1.772453850905516
5555
// SqrtPhi: 1.272019649514069
5656
// Ln2: 0.6931471805599453
57-
// Log2E: 1
57+
// Log2E: 1.4426950408889634
5858
// Ln10: 2.302585092994046
59-
// Log10E: 0
59+
// Log10E: 0.4342944819032518
6060
}

0 commit comments

Comments
 (0)