第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

golang 運(yùn)算符 % 未在 float64 上定義

golang 運(yùn)算符 % 未在 float64 上定義

Go
守候你守候我 2022-06-13 16:35:54
有一個(gè) leetcode 測(cè)試326。使用 java 的數(shù)學(xué)方法的三的冪:public class Solution {    public boolean isPowerOfThree(int n) {        return (Math.log(n) / Math.log(3) + epsilon) % 1 <= 2 * epsilon;    }}當(dāng)我打算將此解決方案轉(zhuǎn)換為 Golang Likeimport "math"func isPowerOfThree(n int) bool {    return (math.Log10(float64(n)) / math.Log10(3)) % 1 == 0.0 }然后出現(xiàn)編譯錯(cuò)誤,例如Line 4: Char 53: invalid operation: math.Log10(float64(n)) / math.Log10(3) % 1 (operator % not defined on float64) (solution.go)我檢查了數(shù)學(xué)包,但沒(méi)有像運(yùn)算符這樣受支持的函數(shù),有沒(méi)有像Golang這樣的%有效運(yùn)算符?%多謝 :)
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊

TLDR: _, frac := math.Modf(f)


您可以func Mod(x, y float64) float64在math包裝中使用。


package main


import (

    "math"

)


func isPowerOfThree(n int) bool {

    return math.Mod((math.Log10(float64(n)) / math.Log10(3)), 1.0) == 0.0 

}

你也可以使用func Modf(f float64) (int float64, frac float64).


package main


import (

    "math"

)


func isPowerOfThree(n int) bool {

    _, frac := math.Modf((math.Log10(float64(n)) / math.Log10(3)))

    return frac == 0.0

}


查看完整回答
反對(duì) 回復(fù) 2022-06-13
  • 1 回答
  • 0 關(guān)注
  • 333 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)