Kotlin java.lang.Math.multiplyFull
Multiply two int values and return the full product as a long.
A simple example
java.lang.Math.multiplyFull
- Start with 2 and 3
- Do this Multiply
- Result 6
fun main() {
println(java.lang.Math.multiplyFull(2, 3))
}
6
Syntax
java.lang.Math.multiplyFull(rows, columns)
Run these examples in Kotlin
Save one example at a time as Lesson.kt. Use Kotlin 2.2 on JDK 21.
kotlinc Lesson.kt -include-runtime -d lesson.jar
java -jar lesson.jarCount cells in a large seating grid
A system must store a batch or grid count in a fixed-width field. Check that the calculation and the final conversion fit before committing the value to the record.
fun main() {
val rows = 50000
val columns = 50000
println(java.lang.Math.multiplyFull(rows, columns))
}
2500000000
A grid with 50000 rows and 50000 columns has 2.5 billion cells, beyond the positive int range.
Count postcards on a print sheet
A print shop lays out eight rows with six postcards in each row. It calculates how many finished cards a complete sheet produces.
Using 8 · 6 gives 48 items for this measurement.
Order bulbs for display panels
A gallery uses twelve panels that each take fifteen bulbs. The supply desk calculates the number of bulbs for a full installation.
Using 12 · 15 gives 180 items for this measurement.
What to watch for
Both operands must fit in int. For long operands choose a different overflow strategy.