1 Star 0 Fork 3

王布衣 / num

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mod.go 699 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-08 08:51 . first commit
package math32
// Mod returns the floating-point remainder of x/y.
// The magnitude of the result is less than y and its
// sign agrees with that of x.
//
// Special cases are:
//
// Mod(±Inf, y) = NaN
// Mod(NaN, y) = NaN
// Mod(x, 0) = NaN
// Mod(x, ±Inf) = x
// Mod(x, NaN) = NaN
func Mod(x, y float32) float32 {
return mod(x, y)
}
func mod(x, y float32) float32 {
if y == 0 || IsInf(x, 0) || IsNaN(x) || IsNaN(y) {
return NaN()
}
if y < 0 {
y = -y
}
yfr, yexp := Frexp(y)
sign := false
r := x
if x < 0 {
r = -x
sign = true
}
for r >= y {
rfr, rexp := Frexp(r)
if rfr < yfr {
rexp = rexp - 1
}
r = r - Ldexp(y, rexp-yexp)
}
if sign {
r = -r
}
return r
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/num.git
git@gitee.com:quant1x/num.git
quant1x
num
num
v0.0.6

搜索帮助

344bd9b3 5694891 D2dac590 5694891