math: simplify comparison in FMA when swapping p and z

Discovered by Junchen Li on CL 246858, the comparison before p and z are
swapped can be simplified from

    pe < ze || (pe == ze && (pm1 < zm1 || (pm1 == zm1 && pm2 < zm2)))

to

    pe < ze || pe == ze && pm1 < zm1

because zm2 is initialized to 0 before the branch.

Change-Id: Iee92d570038df2b0f8941ef6e422a022654ab2d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/247241
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
smasher164 2020-08-06 18:37:10 -04:00 committed by Emmanuel Odeke
parent d10241fcf6
commit 6f90ee36e9

View file

@ -128,7 +128,7 @@ func FMA(x, y, z float64) float64 {
pe -= int32(is62zero)
// Swap addition operands so |p| >= |z|
if pe < ze || (pe == ze && (pm1 < zm1 || (pm1 == zm1 && pm2 < zm2))) {
if pe < ze || pe == ze && pm1 < zm1 {
ps, pe, pm1, pm2, zs, ze, zm1, zm2 = zs, ze, zm1, zm2, ps, pe, pm1, pm2
}