* reload1.c (eliminate_regs_1): Call gen_rtx_raw_SUBREG for SUBREGs
[official-gcc.git] / libgo / go / math / floor.go
blobc40be417152f354d5021f2e436f8596511a307d3
1 // Copyright 2009-2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package math
7 // Floor returns the greatest integer value less than or equal to x.
8 //
9 // Special cases are:
10 // Floor(±0) = ±0
11 // Floor(±Inf) = ±Inf
12 // Floor(NaN) = NaN
14 //extern floor
15 func libc_floor(float64) float64
17 func Floor(x float64) float64 {
18 return libc_floor(x)
21 func floor(x float64) float64 {
22 if x == 0 || IsNaN(x) || IsInf(x, 0) {
23 return x
25 if x < 0 {
26 d, fract := Modf(-x)
27 if fract != 0.0 {
28 d = d + 1
30 return -d
32 d, _ := Modf(x)
33 return d
36 // Ceil returns the least integer value greater than or equal to x.
38 // Special cases are:
39 // Ceil(±0) = ±0
40 // Ceil(±Inf) = ±Inf
41 // Ceil(NaN) = NaN
43 //extern ceil
44 func libc_ceil(float64) float64
46 func Ceil(x float64) float64 {
47 return libc_ceil(x)
50 func ceil(x float64) float64 {
51 return -Floor(-x)
54 // Trunc returns the integer value of x.
56 // Special cases are:
57 // Trunc(±0) = ±0
58 // Trunc(±Inf) = ±Inf
59 // Trunc(NaN) = NaN
61 func Trunc(x float64) float64 {
62 return trunc(x)
65 func trunc(x float64) float64 {
66 if x == 0 || IsNaN(x) || IsInf(x, 0) {
67 return x
69 d, _ := Modf(x)
70 return d