go - 如何在 Golang 中将 Math.Pow 与整数一起使用

标签 go floating-point type-conversion integer

我不断收到错误“ 不能在 math.Pow 的参数中使用(类型 int)作为 float64 类型,不能在 math.Pow 的参数中使用 x(类型 int)作为类型 float64,
无效操作:math.Pow(a, x) % n(float64 和 int 类型不匹配)

func pPrime(n int) bool {
    var nm1 int = n - 1
    var x int = nm1/2
    a := 1;
    for  a < n {
        if  (math.Pow(a, x)) % n == nm1 {
            return true
        }
    }
    return false
}

最佳答案

func powInt(x, y int) int {
    return int(math.Pow(float64(x), float64(y)))
}
以防万一您必须重复使用它并保持清洁。

关于go - 如何在 Golang 中将 Math.Pow 与整数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64108933/

相关文章:

go - Golang 上的包导入错误

python - 轻松漂亮地打印花车?

c++ - 将字符串转换为整数或 double

c# - 将字符串变量值转换为文字

regex - golang正则表达式获取包含搜索字符的字符串

go - 等待 sync.Cond 超时

c - 使用英特尔编译器 (icc) 的四精度数字

c - 以编程方式安全地调整格式字符串中的小数位

java - 在 long 和 double 之间进行类型转换时得到意想不到的结果

go - 如何确保向 channel 发送消息的顺序正确