Skip to content

Commit d79a5ca

Browse files
committed
Fix #5441: Primitive operations on Long with Float argument have different semantics from Java
1 parent 99548bd commit d79a5ca

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

compiler/src/dotty/tools/backend/jvm/BTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ abstract class BTypes {
291291

292292
case LONG =>
293293
if (other.isIntegralType) LONG
294-
else if (other.isRealType) DOUBLE
294+
else if (other.isRealType) other
295295
else uncomparable
296296

297297
case FLOAT =>

tests/run/i5441.check

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1.164309
2+
1.164309
3+
2.3242621

tests/run/i5441.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
def main(args: Array[String]): Unit =
3+
def a(): Float = java.lang.Float.intBitsToFloat(1079290514)
4+
def b(): Long = 1412906027847L
5+
println(b() % a())
6+
println((b().toFloat % a().toFloat).toFloat)
7+
println((b().toDouble % a().toDouble).toFloat)
8+
}

0 commit comments

Comments
 (0)