Ray Rahke
03/16/2024, 6:01 PMfun test(a: Number, y: Number) {
return a / y
}
It errors
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun BigDecimal.div(other: BigDecimal): BigDecimal defined in kotlin
public inline operator fun BigInteger.div(other: BigInteger): BigInteger defined in kotlinkotlin(UNRESOLVED_REFERENCE_WRONG_RECEIVER)
I do not want to change the function signature to fun test(a: Double, y: Double)
I can do this internally to avoid changing the function signature
return a as Double / y as Double
But it is cumbersome.
Does the Number
type not have any way to do division?Youssef Shoaib [MOD]
03/16/2024, 7:00 PMoperator fun Number.div(other: Number): BigDecimal = BigDecimal(toString()) / BigDecimal(other.toString())
You could also convert to Double instead.Arjan van Wieringen
03/16/2024, 7:01 PMRay Rahke
03/17/2024, 1:32 AMRay Rahke
03/17/2024, 1:33 AMRay Rahke
03/17/2024, 1:34 AMNumber - Number
Arjan van Wieringen
03/17/2024, 6:50 AMArjan van Wieringen
03/17/2024, 9:36 AMasdf asdf
03/17/2024, 8:10 PMx.toDouble()
, not x as Double
as that’ll throw a CCE if the number isn’t already a double)Youssef Shoaib [MOD]
03/17/2024, 8:45 PM