Scala FAQ: How to square a number (Int, Double, Float, Long)
Scala math FAQ: How do I square a number in Scala, such as squaring an Int
, Double
, Long
, or Float
?
Solution
You can square a number in Scala in at least two different ways:
- Multiply the number by itself
- Call the Java
Math.pow
function or thescala.math.pow
function