]> Cypherpunks repositories - gostls13.git/commitdiff
pkg/math: undo manual inlining of IsInf and IsNaN
authorLuuk van Dijk <lvd@golang.org>
Wed, 1 Feb 2012 15:08:31 +0000 (16:08 +0100)
committerLuuk van Dijk <lvd@golang.org>
Wed, 1 Feb 2012 15:08:31 +0000 (16:08 +0100)
R=rsc
CC=golang-dev
https://golang.org/cl/5484076

29 files changed:
src/pkg/math/acosh.go
src/pkg/math/asinh.go
src/pkg/math/atan2.go
src/pkg/math/atanh.go
src/pkg/math/cbrt.go
src/pkg/math/dim.go
src/pkg/math/erf.go
src/pkg/math/exp.go
src/pkg/math/expm1.go
src/pkg/math/floor.go
src/pkg/math/frexp.go
src/pkg/math/gamma.go
src/pkg/math/hypot.go
src/pkg/math/j0.go
src/pkg/math/j1.go
src/pkg/math/jn.go
src/pkg/math/ldexp.go
src/pkg/math/lgamma.go
src/pkg/math/log.go
src/pkg/math/log1p.go
src/pkg/math/logb.go
src/pkg/math/mod.go
src/pkg/math/nextafter.go
src/pkg/math/pow.go
src/pkg/math/remainder.go
src/pkg/math/sin.go
src/pkg/math/sincos.go
src/pkg/math/sqrt.go
src/pkg/math/tan.go

index 8d556377f59a4011668e6860248e2d4b35cb4eea..c6c8645e1ae81c631d3ceed0c6f2a6cd8fd8bef8 100644 (file)
@@ -44,11 +44,9 @@ func Acosh(x float64) float64 {
                Ln2   = 6.93147180559945286227e-01 // 0x3FE62E42FEFA39EF
                Large = 1 << 28                    // 2**28
        )
-       // TODO(rsc): Remove manual inlining of IsNaN
-       // when compiler does it for us
        // first case is special case
        switch {
-       case x < 1 || x != x: // x < 1 || IsNaN(x):
+       case x < 1 || IsNaN(x):
                return NaN()
        case x == 1:
                return 0
index f786dd9f8f0996dd4f7339310471f8bab68132d7..0defbb9bef26c7f4c2ffb39c76436e5b1346a169 100644 (file)
@@ -42,10 +42,8 @@ func Asinh(x float64) float64 {
                NearZero = 1.0 / (1 << 28)            // 2**-28
                Large    = 1 << 28                    // 2**28
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
-       if x != x || x > MaxFloat64 || x < -MaxFloat64 { // IsNaN(x) || IsInf(x, 0)
+       if IsNaN(x) || IsInf(x, 0) {
                return x
        }
        sign := false
index 3d1b52a5cca3ec00678f416b26484a647a41d85e..d84b332c9924cf4c0425b94cec8b6e1ac1618e76 100644 (file)
@@ -29,11 +29,9 @@ package math
 func Atan2(y, x float64) float64
 
 func atan2(y, x float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case y != y || x != x: // IsNaN(y) || IsNaN(x):
+       case IsNaN(y) || IsNaN(x):
                return NaN()
        case y == 0:
                if x >= 0 && !Signbit(x) {
@@ -42,22 +40,22 @@ func atan2(y, x float64) float64 {
                return Copysign(Pi, y)
        case x == 0:
                return Copysign(Pi/2, y)
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
-               if x > MaxFloat64 { // IsInf(x, 1) {
+       case IsInf(x, 0):
+               if IsInf(x, 1) {
                        switch {
-                       case y < -MaxFloat64 || y > MaxFloat64: // IsInf(y, -1) || IsInf(y, 1):
+                       case IsInf(y, 0):
                                return Copysign(Pi/4, y)
                        default:
                                return Copysign(0, y)
                        }
                }
                switch {
-               case y < -MaxFloat64 || y > MaxFloat64: // IsInf(y, -1) || IsInf(y, 1):
+               case IsInf(y, 0):
                        return Copysign(3*Pi/4, y)
                default:
                        return Copysign(Pi, y)
                }
-       case y < -MaxFloat64 || y > MaxFloat64: //IsInf(y, 0):
+       case IsInf(y, 0):
                return Copysign(Pi/2, y)
        }
 
index e150673c7001d0945ccc97d11012575166fbc096..5b5d468559bd066e658628e0db86bcdec3d3d3b4 100644 (file)
@@ -46,11 +46,9 @@ package math
 //     Atanh(NaN) = NaN
 func Atanh(x float64) float64 {
        const NearZero = 1.0 / (1 << 28) // 2**-28
-       // TODO(rsc): Remove manual inlining of IsNaN
-       // when compiler does it for us
        // special cases
        switch {
-       case x < -1 || x > 1 || x != x: // x < -1 || x > 1 || IsNaN(x):
+       case x < -1 || x > 1 || IsNaN(x):
                return NaN()
        case x == 1:
                return Inf(1)
index 09edc0eae881ab6f8c6b827898bb03ccde796c3a..8c43f0afbc8858f997d481741cca63fb345573a8 100644 (file)
@@ -33,11 +33,9 @@ func Cbrt(x float64) float64 {
                C3 = 6.46502159e-02
                C4 = 1.412333954e-01
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x == 0 || x != x || x < -MaxFloat64 || x > MaxFloat64: // x == 0 || IsNaN(x) || IsInf(x, 0):
+       case x == 0 || IsNaN(x) || IsInf(x, 0):
                return x
        }
        sign := false
index 16363ac7f5ed065fedb82c03ac438299ae13bcd9..1c634d415f17d27b2deb852423ff8e30e5e4c283 100644 (file)
@@ -26,13 +26,11 @@ func dim(x, y float64) float64 {
 func Max(x, y float64) float64
 
 func max(x, y float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x > MaxFloat64 || y > MaxFloat64: // IsInf(x, 1) || IsInf(y, 1):
+       case IsInf(x, 1) || IsInf(y, 1):
                return Inf(1)
-       case x != x || y != y: // IsNaN(x) || IsNaN(y):
+       case IsNaN(x) || IsNaN(y):
                return NaN()
        case x == 0 && x == y:
                if Signbit(x) {
@@ -55,13 +53,11 @@ func max(x, y float64) float64 {
 func Min(x, y float64) float64
 
 func min(x, y float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x < -MaxFloat64 || y < -MaxFloat64: // IsInf(x, -1) || IsInf(y, -1):
+       case IsInf(x, -1) || IsInf(y, -1):
                return Inf(-1)
-       case x != x || y != y: // IsNaN(x) || IsNaN(y):
+       case IsNaN(x) || IsNaN(y):
                return NaN()
        case x == 0 && x == y:
                if Signbit(x) {
index 6d3d9b7c53730f2634e33d923a27ec87ec692b6f..87c70c2512f616a869d911d4996b35650eb0369e 100644 (file)
@@ -191,14 +191,12 @@ func Erf(x float64) float64 {
                Small    = 1.0 / (1 << 28)        // 2**-28
        )
        // special cases
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        switch {
-       case x != x: // IsNaN(x):
+       case IsNaN(x):
                return NaN()
-       case x > MaxFloat64: // IsInf(x, 1):
+       case IsInf(x, 1):
                return 1
-       case x < -MaxFloat64: // IsInf(x, -1):
+       case IsInf(x, -1):
                return -1
        }
        sign := false
@@ -267,14 +265,12 @@ func Erf(x float64) float64 {
 func Erfc(x float64) float64 {
        const Tiny = 1.0 / (1 << 56) // 2**-56
        // special cases
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        switch {
-       case x != x: // IsNaN(x):
+       case IsNaN(x):
                return NaN()
-       case x > MaxFloat64: // IsInf(x, 1):
+       case IsInf(x, 1):
                return 0
-       case x < -MaxFloat64: // IsInf(x, -1):
+       case IsInf(x, -1):
                return 2
        }
        sign := false
index 2a1710a6d75e7b3a1e70801b19896b0c9b1722b4..f31585fa7700b7e5a1e091508a8d0432eadb99dc 100644 (file)
@@ -100,13 +100,11 @@ func exp(x float64) float64 {
                NearZero  = 1.0 / (1 << 28) // 2**-28
        )
 
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x || x > MaxFloat64: // IsNaN(x) || IsInf(x, 1):
+       case IsNaN(x) || IsInf(x, 1):
                return x
-       case x < -MaxFloat64: // IsInf(x, -1):
+       case IsInf(x, -1):
                return 0
        case x > Overflow:
                return Inf(1)
@@ -145,13 +143,11 @@ func exp2(x float64) float64 {
                Underflow = -1.0740e+03
        )
 
-       // TODO: remove manual inlining of IsNaN and IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x || x > MaxFloat64: // IsNaN(x) || IsInf(x, 1):
+       case IsNaN(x) || IsInf(x, 1):
                return x
-       case x < -MaxFloat64: // IsInf(x, -1):
+       case IsInf(x, -1):
                return 0
        case x > Overflow:
                return Inf(1)
index 15fc25f135649929b4c0e64d1d0f7dc94e7ba8b7..8f56e15cc4fdc6986cdfedfa48ef9291f783871b 100644 (file)
@@ -142,12 +142,10 @@ func expm1(x float64) float64 {
        )
 
        // special cases
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        switch {
-       case x > MaxFloat64 || x != x: // IsInf(x, 1) || IsNaN(x):
+       case IsInf(x, 1) || IsNaN(x):
                return x
-       case x < -MaxFloat64: // IsInf(x, -1):
+       case IsInf(x, -1):
                return -1
        }
 
index a7090f5e4a14a5485674cefb999b4b9f8135b677..9d30629c5e9c08bad32652720cd246116dd88c3b 100644 (file)
@@ -13,9 +13,7 @@ package math
 func Floor(x float64) float64
 
 func floor(x float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
-       if x == 0 || x != x || x > MaxFloat64 || x < -MaxFloat64 { // x == 0 || IsNaN(x) || IsInf(x, 0)
+       if x == 0 || IsNaN(x) || IsInf(x, 0) {
                return x
        }
        if x < 0 {
@@ -50,9 +48,7 @@ func ceil(x float64) float64 {
 func Trunc(x float64) float64
 
 func trunc(x float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
-       if x == 0 || x != x || x > MaxFloat64 || x < -MaxFloat64 { // x == 0 || IsNaN(x) || IsInf(x, 0)
+       if x == 0 || IsNaN(x) || IsInf(x, 0) {
                return x
        }
        d, _ := Modf(x)
index b5458d763933a15cf5aa2f7e431a358569f6376e..0e26feb666bf694965057ccdb3420dbf71eb3df3 100644 (file)
@@ -16,13 +16,11 @@ package math
 func Frexp(f float64) (frac float64, exp int)
 
 func frexp(f float64) (frac float64, exp int) {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
        case f == 0:
                return f, 0 // correctly return -0
-       case f < -MaxFloat64 || f > MaxFloat64 || f != f: // IsInf(f, 0) || IsNaN(f):
+       case IsInf(f, 0) || IsNaN(f):
                return f, 0
        }
        f, exp = normalize(f)
index 7365d8e77541b0446f209e56b13c96444e6697cb..2385a53b8a5cc7819525b85dda1378440918d325 100644 (file)
@@ -121,7 +121,7 @@ func Gamma(x float64) float64 {
        const Euler = 0.57721566490153286060651209008240243104215933593992 // A001620
        // special cases
        switch {
-       case x < -MaxFloat64 || x != x: // IsInf(x, -1) || IsNaN(x):
+       case IsInf(x, -1) || IsNaN(x):
                return x
        case x < -170.5674972726612 || x > 171.61447887182298:
                return Inf(1)
index 233257b522e509f67e3a3e9e13d0eb68c101b419..df4d3eb709108fd168708c567da70ebb60528f91 100644 (file)
@@ -17,13 +17,11 @@ package math
 func Hypot(p, q float64) float64
 
 func hypot(p, q float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case p < -MaxFloat64 || p > MaxFloat64 || q < -MaxFloat64 || q > MaxFloat64: // IsInf(p, 0) || IsInf(q, 0):
+       case IsInf(p, 0) || IsInf(q, 0):
                return Inf(1)
-       case p != p || q != q: // IsNaN(p) || IsNaN(q):
+       case IsNaN(p) || IsNaN(q):
                return NaN()
        }
        if p < 0 {
index 5aaf4ab9cf49c6204ae2c9721f55d1c4e23be90c..c20a9b22a89a761731b6adafe4a3839c1cfa5838 100644 (file)
@@ -89,13 +89,11 @@ func J0(x float64) float64 {
                S03 = 5.13546550207318111446e-07  // 0x3EA13B54CE84D5A9
                S04 = 1.16614003333790000205e-09  // 0x3E1408BCF4745D8F
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x: // IsNaN(x)
+       case IsNaN(x):
                return x
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                return 0
        case x == 0:
                return 1
@@ -171,13 +169,11 @@ func Y0(x float64) float64 {
                V03    = 2.59150851840457805467e-07  // 0x3E91642D7FF202FD
                V04    = 4.41110311332675467403e-10  // 0x3DFE50183BD6D9EF
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x < 0 || x != x: // x < 0 || IsNaN(x):
+       case x < 0 || IsNaN(x):
                return NaN()
-       case x > MaxFloat64: // IsInf(x, 1):
+       case IsInf(x, 1):
                return 0
        case x == 0:
                return Inf(-1)
index 278162e9d35855473263463468a0ffe67b679c7e..7ac186b72aa26cc0f92adf8c15e664708f54f099 100644 (file)
@@ -86,13 +86,11 @@ func J1(x float64) float64 {
                S04 = 5.04636257076217042715e-09  // 0x3E35AC88C97DFF2C
                S05 = 1.23542274426137913908e-11  // 0x3DAB2ACFCFB97ED8
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x: // IsNaN(x)
+       case IsNaN(x):
                return x
-       case x < -MaxFloat64 || x > MaxFloat64 || x == 0: // IsInf(x, 0) || x == 0:
+       case IsInf(x, 0) || x == 0:
                return 0
        }
 
@@ -168,13 +166,11 @@ func Y1(x float64) float64 {
                V03    = 6.22741452364621501295e-09  // 0x3E3ABF1D5BA69A86
                V04    = 1.66559246207992079114e-11  // 0x3DB25039DACA772A
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x < 0 || x != x: // x < 0 || IsNaN(x):
+       case x < 0 || IsNaN(x):
                return NaN()
-       case x > MaxFloat64: // IsInf(x, 1):
+       case IsInf(x, 1):
                return 0
        case x == 0:
                return Inf(-1)
index 1878df5b5a2682e39a21bd094eb59ae72177b901..a7909eb24cdd3f5e1fb23e4db7f996b230b8152d 100644 (file)
@@ -55,13 +55,11 @@ func Jn(n int, x float64) float64 {
                TwoM29 = 1.0 / (1 << 29) // 2**-29 0x3e10000000000000
                Two302 = 1 << 302        // 2**302 0x52D0000000000000
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x: // IsNaN(x)
+       case IsNaN(x):
                return x
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                return 0
        }
        // J(-n, x) = (-1)**n * J(n, x), J(n, -x) = (-1)**n * J(n, x)
@@ -236,13 +234,11 @@ func Jn(n int, x float64) float64 {
 //     Y1(n, NaN) = NaN
 func Yn(n int, x float64) float64 {
        const Two302 = 1 << 302 // 2**302 0x52D0000000000000
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x < 0 || x != x: // x < 0 || IsNaN(x):
+       case x < 0 || IsNaN(x):
                return NaN()
-       case x > MaxFloat64: // IsInf(x, 1)
+       case IsInf(x, 1):
                return 0
        }
 
@@ -299,7 +295,7 @@ func Yn(n int, x float64) float64 {
                a := Y0(x)
                b = Y1(x)
                // quit if b is -inf
-               for i := 1; i < n && b >= -MaxFloat64; i++ { // for i := 1; i < n && !IsInf(b, -1); i++ {
+               for i := 1; i < n && !IsInf(b, -1); i++ {
                        a, b = b, (float64(i+i)/x)*b-a
                }
        }
index 95342301bf271030fe9d681a6068b495bd7e0d0e..b5d2a5e7e83b4431470c7fac10dac9a56202c916 100644 (file)
@@ -14,13 +14,11 @@ package math
 func Ldexp(frac float64, exp int) float64
 
 func ldexp(frac float64, exp int) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
        case frac == 0:
                return frac // correctly return -0
-       case frac < -MaxFloat64 || frac > MaxFloat64 || frac != frac: // IsInf(frac, 0) || IsNaN(frac):
+       case IsInf(frac, 0) || IsNaN(frac):
                return frac
        }
        frac, e := normalize(frac)
index e2bad69dc03d0f8d9fa2245419122f3121f37846..6a02c412d93b603cc6d0abd3e0514ef9e2763a0b 100644 (file)
@@ -183,15 +183,13 @@ func Lgamma(x float64) (lgamma float64, sign int) {
                // Tt = -(tail of Tf)
                Tt = -3.63867699703950536541e-18 // 0xBC50C7CAA48A971F
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        sign = 1
        switch {
-       case x != x: // IsNaN(x):
+       case IsNaN(x):
                lgamma = x
                return
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                lgamma = x
                return
        case x == 0:
index 1d467fbda9259311d24b6c7df340963aab2d1a49..818f00a73fe98534ca9c259e98f0bb9938bef9f2 100644 (file)
@@ -92,11 +92,9 @@ func log(x float64) float64 {
                L7    = 1.479819860511658591e-01   /* 3FC2F112 DF3E5244 */
        )
 
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x || x > MaxFloat64: // IsNaN(x) || IsInf(x, 1):
+       case IsNaN(x) || IsInf(x, 1):
                return x
        case x < 0:
                return NaN()
index dee7f2b64b9d543952d19b92de50bc38a75a060f..12b98684c3d780d0f8084916ac810b95f8c02ef0 100644 (file)
@@ -113,14 +113,12 @@ func log1p(x float64) float64 {
        )
 
        // special cases
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        switch {
-       case x < -1 || x != x: // x < -1 || IsNaN(x): // includes -Inf
+       case x < -1 || IsNaN(x): // includes -Inf
                return NaN()
        case x == -1:
                return Inf(-1)
-       case x > MaxFloat64: // IsInf(x, 1):
+       case IsInf(x, 1):
                return Inf(1)
        }
 
index 072281ddf9f852de98fbe8793575e4cefd759524..d32f9f1000c790d042cb586c7e7e47c7af9b7c27 100644 (file)
@@ -11,15 +11,13 @@ package math
 //     Logb(0) = -Inf
 //     Logb(NaN) = NaN
 func Logb(x float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
        case x == 0:
                return Inf(-1)
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                return Inf(1)
-       case x != x: // IsNaN(x):
+       case IsNaN(x):
                return x
        }
        return float64(ilogb(x))
@@ -32,15 +30,13 @@ func Logb(x float64) float64 {
 //     Ilogb(0) = MinInt32
 //     Ilogb(NaN) = MaxInt32
 func Ilogb(x float64) int {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
        case x == 0:
                return MinInt32
-       case x != x: // IsNaN(x):
+       case IsNaN(x):
                return MaxInt32
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                return MaxInt32
        }
        return ilogb(x)
index c1f244d67ba4e9d04a8f1d2f8677b5f14b365f5c..e1a414e5f9cbace7374d13e6b3ce0e45c903c7e5 100644 (file)
@@ -21,9 +21,7 @@ package math
 func Mod(x, y float64) float64
 
 func mod(x, y float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us.
-       if y == 0 || x > MaxFloat64 || x < -MaxFloat64 || x != x || y != y { // y == 0 || IsInf(x, 0) || IsNaN(x) || IsNan(y)
+       if y == 0 || IsInf(x, 0) || IsNaN(x) || IsNaN(y) {
                return NaN()
        }
        if y < 0 {
index e7723baacfb7e108e00df99de6b5726402a6c820..7c4b5bcdfef7eb2a5a58e0a73d285aada804f01c 100644 (file)
@@ -11,10 +11,8 @@ package math
 //      Nextafter(NaN, y) = NaN
 //      Nextafter(x, NaN) = NaN
 func Nextafter(x, y float64) (r float64) {
-       // TODO(rsc): Remove manual inlining of IsNaN
-       // when compiler does it for us
        switch {
-       case x != x || y != y: // IsNaN(x) || IsNaN(y): // special case
+       case IsNaN(x) || IsNaN(y): // special case
                r = NaN()
        case x == y:
                r = x
index f0f52c5cd4b034385da788bf7107cad23106a7f6..77af25648abf9d3c24c9828e6b6e8883dd484b1e 100644 (file)
@@ -36,8 +36,6 @@ func isOddInt(x float64) bool {
 //     Pow(-Inf, y) = Pow(-0, -y)
 //     Pow(x, y) = NaN for finite x < 0 and finite non-integer y
 func Pow(x, y float64) float64 {
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        switch {
        case y == 0 || x == 1:
                return 1
@@ -47,7 +45,7 @@ func Pow(x, y float64) float64 {
                return Sqrt(x)
        case y == -0.5:
                return 1 / Sqrt(x)
-       case x != x || y != y: // IsNaN(x) || IsNaN(y):
+       case IsNaN(x) || IsNaN(y):
                return NaN()
        case x == 0:
                switch {
@@ -62,7 +60,7 @@ func Pow(x, y float64) float64 {
                        }
                        return 0
                }
-       case y > MaxFloat64 || y < -MaxFloat64: // IsInf(y, 0):
+       case IsInf(y, 0):
                switch {
                case x == -1:
                        return 1
@@ -71,7 +69,7 @@ func Pow(x, y float64) float64 {
                default:
                        return Inf(1)
                }
-       case x > MaxFloat64 || x < -MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                if IsInf(x, -1) {
                        return Pow(1/x, -y) // Pow(-0, -y)
                }
index 69d23e58e42a695d3f873020d5996ca77a14d953..41efd79085eba74d3c6cb74d1b5544831451b02d 100644 (file)
@@ -41,13 +41,11 @@ func remainder(x, y float64) float64 {
                Tiny    = 4.45014771701440276618e-308 // 0x0020000000000000
                HalfMax = MaxFloat64 / 2
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x || y != y || x < -MaxFloat64 || x > MaxFloat64 || y == 0: // IsNaN(x) || IsNaN(y) || IsInf(x, 0) || y == 0:
+       case IsNaN(x) || IsNaN(y) || IsInf(x, 0) || y == 0:
                return NaN()
-       case y < -MaxFloat64 || y > MaxFloat64: // IsInf(y):
+       case IsInf(y, 0):
                return x
        }
        sign := false
index 176ac229abb681ea124a3761110c6f7522f74526..8beb8bbe3410ca98944b180d37ba4956ea32cb51 100644 (file)
@@ -123,11 +123,9 @@ func cos(x float64) float64 {
                PI4C = 2.69515142907905952645E-15                            // 0x3ce8469898cc5170,
                M4PI = 1.273239544735162542821171882678754627704620361328125 // 4/pi
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x != x || x < -MaxFloat64 || x > MaxFloat64: // IsNaN(x) || IsInf(x, 0):
+       case IsNaN(x) || IsInf(x, 0):
                return NaN()
        }
 
@@ -182,13 +180,11 @@ func sin(x float64) float64 {
                PI4C = 2.69515142907905952645E-15                            // 0x3ce8469898cc5170,
                M4PI = 1.273239544735162542821171882678754627704620361328125 // 4/pi
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x == 0 || x != x: // x == 0 || IsNaN():
+       case x == 0 || IsNaN(x):
                return x // return ±0 || NaN()
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                return NaN()
        }
 
index ff6c3281d614ddf8e8483accc4af275ee96ebcb4..7300429207c3863a85de340b3567017b7811e29c 100644 (file)
@@ -21,13 +21,11 @@ func sincos(x float64) (sin, cos float64) {
                PI4C = 2.69515142907905952645E-15                            // 0x3ce8469898cc5170,
                M4PI = 1.273239544735162542821171882678754627704620361328125 // 4/pi
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
        case x == 0:
                return x, 1 // return ±0.0, 1.0
-       case x != x || x < -MaxFloat64 || x > MaxFloat64: // IsNaN(x) || IsInf(x, 0):
+       case IsNaN(x) || IsInf(x, 0):
                return NaN(), NaN()
        }
 
index d0b5535f2927ab27df5c95314584aa5f4b290497..21336df2ae0f3aefe2a2e184a8d5613bb49822d2 100644 (file)
@@ -100,10 +100,8 @@ func Sqrt(x float64) float64
 //     Sqrt(NaN) = NaN
 func sqrt(x float64) float64 {
        // special cases
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        switch {
-       case x == 0 || x != x || x > MaxFloat64: // x == 0 || IsNaN(x) || IsInf(x, 1):
+       case x == 0 || IsNaN(x) || IsInf(x, 1):
                return x
        case x < 0:
                return NaN()
index 4e722e1ad216dca0ee6f76c1af2b6b9518b72a05..b2f29cc3b3033384e6a161e4a225ccc3dbf57053 100644 (file)
@@ -88,13 +88,11 @@ func tan(x float64) float64 {
                PI4C = 2.69515142907905952645E-15                            // 0x3ce8469898cc5170,
                M4PI = 1.273239544735162542821171882678754627704620361328125 // 4/pi
        )
-       // TODO(rsc): Remove manual inlining of IsNaN, IsInf
-       // when compiler does it for us
        // special cases
        switch {
-       case x == 0 || x != x: // x == 0 || IsNaN():
+       case x == 0 || IsNaN(x):
                return x // return ±0 || NaN()
-       case x < -MaxFloat64 || x > MaxFloat64: // IsInf(x, 0):
+       case IsInf(x, 0):
                return NaN()
        }