Skip to content
Related Articles

Related Articles

Calculating smallest and largest an in Julia – nextpow() and prevpow() Methods
  • Last Updated : 01 Apr, 2020

The nextpow() is an inbuilt function in julia which is used to return the smallest a^n not less than x, where n is a non-negative integer, a must be greater than 1, and x must be greater than 0.

Syntax: nextpow(a, x)

Parameters:

  • a: Specified number greater than 1.
  • x: Specified number greater than 0.

Returns: It returns the smallest a^n.

Example:






# Julia program to illustrate 
# the use of nextpow() method
   
# Getting the smallest a ^ n
println(nextpow(2, 8))
println(nextpow(2, 10))
println(nextpow(3, 8))
println(nextpow(5, 15))

Output:

8
16
9
25

prevpow()

The prevpow() is an inbuilt function in julia which is used to return the largest a^n not greater than x, where n is a non-negative integer, a must be greater than 1, and x must not be less than 1.

Syntax: prevpow(a, x)

Parameters:

  • a: Specified number greater than 1.
  • x: Specified number must not be less than 1.

Returns: It returns the largest a^n.

Example:




# Julia program to illustrate 
# the use of prevpow() method
   
# Getting the largest a ^ n
println(prevpow(2, 8))
println(prevpow(2, 6))
println(prevpow(3, 8))
println(prevpow(5, 15))

Output:

8
4
3
5

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :