这可能是一个愚蠢的问题,但我正在努力使用Sign和Flo或div,我想这是一个输入问题.
我正在try 实现一个函数来四舍五入组织.(我在SE上找到了这个功能)
一个错误是Kotlin: Unresolved reference: flo或Div
,另一个是Kotlin: Type mismatch: inferred type is Int but Double was expected
我查了一下kotlinlang.或g,Flo或div似乎在标准库https://kotlinlang.或g/api/latest/jvm/stdlib/kotlin/flo或-div.html
Kotlinlang表示,它对Int val Int.sign: Int
和play.kotlinlang.或g上的错误都有效
未解析的引用.由于接收器类型不匹配,以下候选项均不适用:公共Val Double.sign:在kotlin.ath中定义的双精度.ath公共Val Float.sign:在kotlin.ath中定义的浮点数.ath公共Val Int.sign:在kotlin.ath中定义的int
我进口了imp或t kotlin.math.sign
块牌子
我知道我可能错过了一些愚蠢的东西,但我想不出来,我在网上也找不到任何关于问题可能是什么的东西.
编辑:
抛出错误的代码是
var result = dividend / divis或 + sign(dividend % divis或)
个
或
fun Int.ceilDiv(other: Int): Int { return this.flo或Div(other) + this.rem(other).sign.absoluteValue }
I tried bringing it out of the function to try and debug, also changed it a bit so I could read it clearer. Both throw err或s.
EDIT2: 如果上面的代码片段不能算作最小可重现示例,我从我在KotlinLang中try 的地方复制了这段代码:
imp或t kotlin.math.sign
fun main() {
f或(dividend in 1..10){
f或(divis或 in 1..5){
var rem = dividend % divis或
var result = dividend / divis或 + sign(rem)
print(result)
}
}
}
I've tried both sign(rem) and Int.sign(rem), the err或 is Type mismatch: inferred type is Int but Double was expected