diff options
| author | Charles L. Dorian <cldorian@gmail.com> | 2010-01-11 21:28:02 -0800 |
|---|---|---|
| committer | Charles L. Dorian <cldorian@gmail.com> | 2010-01-11 21:28:02 -0800 |
| commit | b53d3e5a5b414f7db20741e688d807002d596a35 (patch) | |
| tree | 44eb800d03bc7a42d5d2262afdb13312cc5cdb06 /src/pkg/math/floor.go | |
| parent | 32e28a4030cfa931528146f6a0efe0eaba7411e5 (diff) | |
| download | golang-b53d3e5a5b414f7db20741e688d807002d596a35.tar.gz | |
math: special cases for Ceil, Exp, Floor, Log, Log10
Added special case tests to all_test.go. Added tests to Floor,
in-lined tests in Exp and Log.
R=rsc
CC=golang-dev
http://codereview.appspot.com/184081
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/math/floor.go')
| -rw-r--r-- | src/pkg/math/floor.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/pkg/math/floor.go b/src/pkg/math/floor.go index 2acf1e042..c5e496d8f 100644 --- a/src/pkg/math/floor.go +++ b/src/pkg/math/floor.go @@ -6,7 +6,15 @@ package math // Floor returns the greatest integer value less than or equal to x. +// +// Special cases are: +// Floor(+Inf) = +Inf +// Floor(-Inf) = -Inf +// Floor(NaN) = NaN func Floor(x float64) float64 { + if x != x || x > MaxFloat64 || x < -MaxFloat64 { // IsNaN(x) || IsInf(x, 0) + return x + } if x < 0 { d, fract := Modf(-x) if fract != 0.0 { @@ -19,4 +27,9 @@ func Floor(x float64) float64 { } // Ceil returns the least integer value greater than or equal to x. +// +// Special cases are: +// Ceil(+Inf) = +Inf +// Ceil(-Inf) = -Inf +// Ceil(NaN) = NaN func Ceil(x float64) float64 { return -Floor(-x) } |
