With Long Data Types
Below is the Scala program to implement exponentiation with long data types:
//Scala Program to use Exponential
import scala.math.BigDecimal
val base = 5L // Long data type
val exponent = 2
val result = BigDecimal(base).pow(exponent)
println(result)
Output:
25
How to do Exponentiation in Scala?
This article focuses on discussing implementing exponentiation in Scala. The math.pow()
function from the scala.math
package is used for exponentiation in Scala.
Table of Content
- Basic Approach
- Using BigDecimal
- With Long Data Types
Syntax:
val result = pow(base, exponent)