Kotlin pow()
Published Oct 24, 2023
Contribute to Docs
The pow() method in Kotlin’s math class is used to calculate a number raised to the power of another number. It takes two parameters - the base (number to be raised to a power) and the exponent (the power to which the base is raised). The base and component can be either a double or float but not an integer.
Syntax
import kotlin.math.*
fun base: Double.pow(exponent: Double): Double
fun base: Double.pow(exponent: Float): Float
base: The base number.exponent: The number that raises the base number.
The pow() method returns a value of type double or float.
Example
This example shows how use the pow() method to calculate 5.0 raised to the power of 2.5:
import kotlin.math.powfun main() {val base = 5.0val exponent = 2.5val result = base.pow(exponent)println("$base raised to the power of $exponent is $result.")}
The code above will result in the following output:
5.0 raised to the power of 2.5 is 55.90169943749474.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours