Go C+的等价物是什么+;围棋中的fmod?

Go C+的等价物是什么+;围棋中的fmod?,go,Go,fmod计算除法余数返回除法的浮点余数 数字/小数(四舍五入至零): fmod=数值-tquot*denom 其中tquot是以下各项的截断(即,向零舍入)结果: 数字/名称 Mod返回x/y的浮点余数。地震的震级 结果小于y,其符号与x的符号一致 比如说, package main /* #cgo LDFLAGS: -lm #include <math.h> #include <stdio.h> double fmodC(double x, double

fmod计算除法余数返回除法的浮点余数 数字/小数(四舍五入至零):

fmod=数值-tquot*denom

其中tquot是以下各项的截断(即,向零舍入)结果: 数字/名称

Mod返回x/y的浮点余数。地震的震级 结果小于y,其符号与x的符号一致


比如说,

package main

/*
#cgo LDFLAGS: -lm

#include <math.h>
#include <stdio.h>

double fmodC(double x, double y) {
    double mod = fmod(x, y);
    printf("%f\n", mod);
    return mod;
}
*/
import "C"

import (
    "fmt"
    "math"
)

func fmodGo(x, y float64) float64 {
    mod := math.Mod(x, y)
    fmt.Printf("%f\n", mod)
    return mod
}

func main() {
    x, y := 42.0*3.14159, -2.718
    fmt.Println(x, y)
    modC := C.fmodC(C.double(x), C.double(y))
    modGo := fmodGo(x, y)
    fmt.Println(float64(modC) == modGo)

    // fmod = numer - tquot * denom
    numer := x
    denom := y
    tquot := float64(int64(x / y))
    fmod := math.Mod(numer, denom)
    fmt.Println(fmod == numer-tquot*denom)
}
func Mod(x, y float64) float64
package main

/*
#cgo LDFLAGS: -lm

#include <math.h>
#include <stdio.h>

double fmodC(double x, double y) {
    double mod = fmod(x, y);
    printf("%f\n", mod);
    return mod;
}
*/
import "C"

import (
    "fmt"
    "math"
)

func fmodGo(x, y float64) float64 {
    mod := math.Mod(x, y)
    fmt.Printf("%f\n", mod)
    return mod
}

func main() {
    x, y := 42.0*3.14159, -2.718
    fmt.Println(x, y)
    modC := C.fmodC(C.double(x), C.double(y))
    modGo := fmodGo(x, y)
    fmt.Println(float64(modC) == modGo)

    // fmod = numer - tquot * denom
    numer := x
    denom := y
    tquot := float64(int64(x / y))
    fmod := math.Mod(numer, denom)
    fmt.Println(fmod == numer-tquot*denom)
}
131.94678 -2.718
1.482780
1.482780
true
true