Skip to content

Commit 1306911

Browse files
authored
Merge pull request #9962 from prolativ/fix-long-and-float-max-value-type
Fix #5441: Primitive operations on Long with Float argument have different semantics from Java
2 parents c6bcfae + 9d96d4b commit 1306911

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,12 @@ abstract class BTypes {
290290
}
291291

292292
case LONG =>
293-
if (other.isIntegralType) LONG
294-
else if (other.isRealType) DOUBLE
295-
else uncomparable
293+
other match {
294+
case INT | BYTE | LONG | CHAR | SHORT => LONG
295+
case DOUBLE => DOUBLE
296+
case FLOAT => FLOAT
297+
case _ => uncomparable
298+
}
296299

297300
case FLOAT =>
298301
if (other == DOUBLE) DOUBLE

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)