blob: 493f8c56154ae3f5881e559ba720097714bbeb5c [file] [log] [blame]
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +01001// Copyright 2018 The CUE Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package math
16
17import "math"
18
19// TODO: use apd
20
21// Floor returns the greatest integer value less than or equal to x.
22//
23// Special cases are:
24// Floor(±0) = ±0
25// Floor(±Inf) = ±Inf
26// Floor(NaN) = NaN
27func Floor(x float64) float64 {
28 return math.Floor(x)
29}
30
31// Ceil returns the least integer value greater than or equal to x.
32//
33// Special cases are:
34// Ceil(±0) = ±0
35// Ceil(±Inf) = ±Inf
36// Ceil(NaN) = NaN
37func Ceil(x float64) float64 {
38 return math.Ceil(x)
39}
40
41// Trunc returns the integer value of x.
42//
43// Special cases are:
44// Trunc(±0) = ±0
45// Trunc(±Inf) = ±Inf
46// Trunc(NaN) = NaN
47func Trunc(x float64) float64 {
48 return math.Trunc(x)
49}
50
51// Round returns the nearest integer, rounding half away from zero.
52//
53// Special cases are:
54// Round(±0) = ±0
55// Round(±Inf) = ±Inf
56// Round(NaN) = NaN
57func Round(x float64) float64 {
58 return math.Round(x)
59}
60
61// RoundToEven returns the nearest integer, rounding ties to even.
62//
63// Special cases are:
64// RoundToEven(±0) = ±0
65// RoundToEven(±Inf) = ±Inf
66// RoundToEven(NaN) = NaN
67func RoundToEven(x float64) float64 {
68 return math.RoundToEven(x)
69}