mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
SVN=114204
This commit is contained in:
parent
cb87526ce3
commit
2181098189
19 changed files with 1188 additions and 0 deletions
48
src/lib/math/fmod.go
Normal file
48
src/lib/math/fmod.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package fmod
|
||||
|
||||
import sys "sys"
|
||||
export fmod
|
||||
|
||||
/*
|
||||
floating-point mod func without infinity or NaN checking
|
||||
*/
|
||||
|
||||
func
|
||||
fmod(x, y double) double
|
||||
{
|
||||
var yexp, rexp int;
|
||||
var r, yfr, rfr double;
|
||||
var sign bool;
|
||||
|
||||
if y == 0 {
|
||||
return x;
|
||||
}
|
||||
if y < 0 {
|
||||
y = -y;
|
||||
}
|
||||
|
||||
yexp,yfr = sys.frexp(y);
|
||||
sign = false;
|
||||
if x < 0 {
|
||||
r = -x;
|
||||
sign = true;
|
||||
} else {
|
||||
r = x;
|
||||
}
|
||||
|
||||
for r >= y {
|
||||
rexp,rfr = sys.frexp(r);
|
||||
if rfr < yfr {
|
||||
rexp = rexp - 1;
|
||||
}
|
||||
r = r - sys.ldexp(y, rexp-yexp);
|
||||
}
|
||||
if sign {
|
||||
r = -r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue