diff options
| author | Russ Cox <rsc@golang.org> | 2014-11-15 08:00:38 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-11-15 08:00:38 -0500 |
| commit | 0fcf54b3d2bc42a947c65e9a520d078b671f8432 (patch) | |
| tree | 071014526059897ceef47c43e5a24ddc0a57b636 /src/runtime/complex.go | |
| parent | 9ef4e5610809780555260f386d6e20f3df87c6ce (diff) | |
| parent | 5fce15a2a3cd94427bb9979d73acf14013ec7f31 (diff) | |
| download | go-0fcf54b3d2bc42a947c65e9a520d078b671f8432.tar.xz | |
[dev.garbage] all: merge dev.cc into dev.garbage
The garbage collector is now written in Go.
There is plenty to clean up (just like on dev.cc).
all.bash passes on darwin/amd64, darwin/386, linux/amd64, linux/386.
TBR=rlh
R=austin, rlh, bradfitz
CC=golang-codereviews
https://golang.org/cl/173250043
Diffstat (limited to 'src/runtime/complex.go')
| -rw-r--r-- | src/runtime/complex.go | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/runtime/complex.go b/src/runtime/complex.go index ec50f89470..73f1161a50 100644 --- a/src/runtime/complex.go +++ b/src/runtime/complex.go @@ -4,28 +4,47 @@ package runtime +func isposinf(f float64) bool { return f > maxFloat64 } +func isneginf(f float64) bool { return f < -maxFloat64 } +func isnan(f float64) bool { return f != f } + +func nan() float64 { + var f float64 = 0 + return f / f +} + +func posinf() float64 { + var f float64 = maxFloat64 + return f * f +} + +func neginf() float64 { + var f float64 = maxFloat64 + return -f * f +} + func complex128div(n complex128, d complex128) complex128 { // Special cases as in C99. - ninf := real(n) == posinf || real(n) == neginf || - imag(n) == posinf || imag(n) == neginf - dinf := real(d) == posinf || real(d) == neginf || - imag(d) == posinf || imag(d) == neginf + ninf := isposinf(real(n)) || isneginf(real(n)) || + isposinf(imag(n)) || isneginf(imag(n)) + dinf := isposinf(real(d)) || isneginf(real(d)) || + isposinf(imag(d)) || isneginf(imag(d)) - nnan := !ninf && (real(n) != real(n) || imag(n) != imag(n)) - dnan := !dinf && (real(d) != real(d) || imag(d) != imag(d)) + nnan := !ninf && (isnan(real(n)) || isnan(imag(n))) + dnan := !dinf && (isnan(real(d)) || isnan(imag(d))) switch { case nnan || dnan: - return complex(nan, nan) + return complex(nan(), nan()) case ninf && !dinf: - return complex(posinf, posinf) + return complex(posinf(), posinf()) case !ninf && dinf: return complex(0, 0) case real(d) == 0 && imag(d) == 0: if real(n) == 0 && imag(n) == 0 { - return complex(nan, nan) + return complex(nan(), nan()) } else { - return complex(posinf, posinf) + return complex(posinf(), posinf()) } default: // Standard complex arithmetic, factored to avoid unnecessary overflow. |
