]> Cypherpunks repositories - gostls13.git/commitdiff
math: simplify the code
authorkakulisen <lziqiang1@gmail.com>
Thu, 14 May 2020 08:20:58 +0000 (16:20 +0800)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Sat, 15 Aug 2020 02:20:42 +0000 (02:20 +0000)
Simplifying some code without compromising performance.
My CPU is Intel Xeon Gold 6161, 2.20GHz, 64-bit operating system.
The memory is 8GB. This is my test environment, I hope to help you judge.

Benchmark:

name      old time/op    new time/op    delta
Log1p-4    21.8ns ± 5%    21.8ns ± 4%   ~     (p=0.973 n=20+20)

Change-Id: Icd8f96f1325b00007602d114300b92d4c57de409
Reviewed-on: https://go-review.googlesource.com/c/go/+/233940
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/log1p.go

index c4ec61b2259ebdf431d59c9b4911a1fce69554c1..e34e1ff4f2f96deececc6fa39807d656760605a3 100644 (file)
@@ -122,10 +122,7 @@ func log1p(x float64) float64 {
                return Inf(1)
        }
 
-       absx := x
-       if absx < 0 {
-               absx = -absx
-       }
+       absx := Abs(x)
 
        var f float64
        var iu uint64