math: document more special cases Acosh, Asinh, Atanh, Ceil, Floor, Trunc, Mod and Remainder affected. These changes add some non-finite arguments and results (and -0.0 results). R=rsc, golang-dev CC=golang-dev https://golang.org/cl/5469046
diff --git a/src/pkg/math/acosh.go b/src/pkg/math/acosh.go index 7e8740b..8d55637 100644 --- a/src/pkg/math/acosh.go +++ b/src/pkg/math/acosh.go
@@ -36,6 +36,7 @@ // Acosh(x) calculates the inverse hyperbolic cosine of x. // // Special cases are: +// Acosh(+Inf) = +Inf // Acosh(x) = NaN if x < 1 // Acosh(NaN) = NaN func Acosh(x float64) float64 {
diff --git a/src/pkg/math/asinh.go b/src/pkg/math/asinh.go index d697946..f786dd9 100644 --- a/src/pkg/math/asinh.go +++ b/src/pkg/math/asinh.go
@@ -33,6 +33,7 @@ // Asinh(x) calculates the inverse hyperbolic sine of x. // // Special cases are: +// Asinh(±0) = ±0 // Asinh(±Inf) = ±Inf // Asinh(NaN) = NaN func Asinh(x float64) float64 {
diff --git a/src/pkg/math/atanh.go b/src/pkg/math/atanh.go index ed38fca..e150673 100644 --- a/src/pkg/math/atanh.go +++ b/src/pkg/math/atanh.go
@@ -39,9 +39,10 @@ // Atanh(x) calculates the inverse hyperbolic tangent of x. // // Special cases are: -// Atanh(x) = NaN if x < -1 or x > 1 // Atanh(1) = +Inf +// Atanh(±0) = ±0 // Atanh(-1) = -Inf +// Atanh(x) = NaN if x < -1 or x > 1 // Atanh(NaN) = NaN func Atanh(x float64) float64 { const NearZero = 1.0 / (1 << 28) // 2**-28
diff --git a/src/pkg/math/floor.go b/src/pkg/math/floor.go index 8de4d7e..e5b52c4 100644 --- a/src/pkg/math/floor.go +++ b/src/pkg/math/floor.go
@@ -7,6 +7,7 @@ // Floor returns the greatest integer value less than or equal to x. // // Special cases are: +// Floor(±0) = ±0 // Floor(±Inf) = ±Inf // Floor(NaN) = NaN func Floor(x float64) float64 { @@ -29,6 +30,7 @@ // Ceil returns the least integer value greater than or equal to x. // // Special cases are: +// Ceil(±0) = ±0 // Ceil(±Inf) = ±Inf // Ceil(NaN) = NaN func Ceil(x float64) float64 { return -Floor(-x) } @@ -36,6 +38,7 @@ // Trunc returns the integer value of x. // // Special cases are: +// Trunc(±0) = ±0 // Trunc(±Inf) = ±Inf // Trunc(NaN) = NaN func Trunc(x float64) float64 {
diff --git a/src/pkg/math/mod.go b/src/pkg/math/mod.go index 6b16abe..0dd5d06 100644 --- a/src/pkg/math/mod.go +++ b/src/pkg/math/mod.go
@@ -13,8 +13,11 @@ // sign agrees with that of x. // // Special cases are: -// if x is not finite, Mod returns NaN -// if y is 0 or NaN, Mod returns NaN +// Mod(±Inf, y) = NaN +// Mod(NaN, y) = NaN +// Mod(x, 0) = NaN +// Mod(x, ±Inf) = x +// Mod(x, NaN) = NaN func Mod(x, y float64) float64 { // TODO(rsc): Remove manual inlining of IsNaN, IsInf // when compiler does it for us.
diff --git a/src/pkg/math/nextafter.go b/src/pkg/math/nextafter.go index 8611434..ae1267f 100644 --- a/src/pkg/math/nextafter.go +++ b/src/pkg/math/nextafter.go
@@ -10,6 +10,7 @@ // Special cases are: // Nextafter(NaN, y) = NaN // Nextafter(x, NaN) = NaN +// Nextafter(0, y) = -0, if y < 0 func Nextafter(x, y float64) (r float64) { // TODO(rsc): Remove manual inlining of IsNaN // when compiler does it for us
diff --git a/src/pkg/math/remainder.go b/src/pkg/math/remainder.go index 7fb8a12..8d8a746 100644 --- a/src/pkg/math/remainder.go +++ b/src/pkg/math/remainder.go
@@ -29,11 +29,11 @@ // Remainder returns the IEEE 754 floating-point remainder of x/y. // // Special cases are: -// Remainder(x, NaN) = NaN +// Remainder(±Inf, y) = NaN // Remainder(NaN, y) = NaN -// Remainder(Inf, y) = NaN // Remainder(x, 0) = NaN -// Remainder(x, Inf) = x +// Remainder(x, ±Inf) = x +// Remainder(x, NaN) = NaN func Remainder(x, y float64) float64 { const ( Tiny = 4.45014771701440276618e-308 // 0x0020000000000000