Skip to content

Commit

Permalink
pkg/math: reuse Ln2 and Ln10 in Log2E and Log10E
Browse files Browse the repository at this point in the history
Upstream Go's math package has always used these simple divisions,
and now that pkg/gen.go can resolve complex expressions via go/types,
we can use exactly the same expression in our package.

This change is a no-op, which is guaranteed by Example_constants.
The new code is a lot less verbose and easier to understand, too.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I93dbeb26d3b496c724d53c95afad01f8583e56e0
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/557323
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Sep 4, 2023
1 parent 2091170 commit fe2f216
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ const (
SqrtPhi = 1.27201964951406896425242246173749149171560804184009624861664038 // https://oeis.org/A139339

Ln2 = 0.693147180559945309417232121458176568075500134360255254120680009 // https://oeis.org/A002162
Log2E = 1000000000000000000000000000000000000000000000000000000000000000.0 / 693147180559945309417232121458176568075500134360255254120680009
Log2E = 1 / Ln2
Ln10 = 2.30258509299404568401799145468436420760110148862877297603332790 // https://oeis.org/A002392
Log10E = 10000000000000000000000000000000000000000000000000000000000000.0 / 23025850929940456840179914546843642076011014886287729760333279
Log10E = 1 / Ln10
)

// Copysign returns a value with the magnitude
Expand Down

0 comments on commit fe2f216

Please sign in to comment.