Commit 94b0342f authored by Charles L. Dorian's avatar Charles L. Dorian Committed by Russ Cox

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
parent 60f564fc
......@@ -36,6 +36,7 @@ package math
// 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 {
......
......@@ -33,6 +33,7 @@ package math
// 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 {
......
......@@ -39,9 +39,10 @@ package math
// 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
......
......@@ -7,6 +7,7 @@ package math
// 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 @@ func Floor(x float64) float64 {
// 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 @@ func Ceil(x float64) float64 { return -Floor(-x) }
// Trunc returns the integer value of x.
//
// Special cases are:
// Trunc(±0) = ±0
// Trunc(±Inf) = ±Inf
// Trunc(NaN) = NaN
func Trunc(x float64) float64 {
......
......@@ -13,8 +13,11 @@ package math
// 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.
......
......@@ -10,6 +10,7 @@ package math
// 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
......
......@@ -29,11 +29,11 @@ package math
// 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment