* doc/invoke.texi (RS/6000 and PowerPC Options): Document -mhtm and
[official-gcc.git] / libgo / go / math / mod.go
blob0b208f4eda3b43e12fa94efb4b8c83f86334746d
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 /*
8 Floating-point mod function.
9 */
11 // Mod returns the floating-point remainder of x/y.
12 // The magnitude of the result is less than y and its
13 // sign agrees with that of x.
15 // Special cases are:
16 // Mod(±Inf, y) = NaN
17 // Mod(NaN, y) = NaN
18 // Mod(x, 0) = NaN
19 // Mod(x, ±Inf) = x
20 // Mod(x, NaN) = NaN
22 //extern fmod
23 func libc_fmod(float64, float64) float64
25 func Mod(x, y float64) float64 {
26 return libc_fmod(x, y)
29 func mod(x, y float64) float64 {
30 if y == 0 || IsInf(x, 0) || IsNaN(x) || IsNaN(y) {
31 return NaN()
33 if y < 0 {
34 y = -y
37 yfr, yexp := Frexp(y)
38 sign := false
39 r := x
40 if x < 0 {
41 r = -x
42 sign = true
45 for r >= y {
46 rfr, rexp := Frexp(r)
47 if rfr < yfr {
48 rexp = rexp - 1
50 r = r - Ldexp(y, rexp-yexp)
52 if sign {
53 r = -r
55 return r