Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
functions
communitycreator

What is the power() function in Euphoria?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

Raising an element to a particular exponent power is a common practice in arithmetic. When conducting an arithmetical computation, we may need to know when to get the value of a number to a particular exponent. We can easily achieve this considering two values in Euphoria, using the power function.

The power function

This function is used to carry out an exponentiation operation. The power() function raises a value, the base, to the power of another value, the exponent, and returns the output of such an operation.

Syntax

power(baseValue, exponentValue)

Parameters

  • baseValue: This represents the value of the base which will be exponentiated.
  • exponentValue: This is the value of the exponent, which is the power that the base will be raised to.

Return values

This function will return an exponentiated object value.

Common errors

The following actions can cause this function to throw an exception error.

  • When a base value that is negative is raised to a value that is not an integer, it causes an error because the result is undefined.

  • Raising 0 to a negative power causes an error because it is similar to saying that zero is divided by something, which is mathematically erroneous.

  • Doing something like Power(0,0) is an illegal operation because zero values do not really represent unique quantities.

Code

Now that our understanding of this function is clear, let’s see some code examples.

--so let just go straight and print to screen some power output
puts(1,"This is the output of 2 to power of 5 : ")
print(1,power(2,5))
puts(1,"\n Result of 2 to power of 10, and 5 power 2 : ")
print(1,power({2,5},{10,2}))
puts(1,"\n This is the output of 4 to power of -3 : ")
print(1,power(4 ,-3))

Explanation

Several instances where different values are raised to the power of different exponents are showcased in the code above.

  • In line 2, we see a simple comment.
  • In lines 3, 5 and 7, the puts() function prints some new lines and comments to the screen.
  • Lines 4, 6, and 8 contain the print() function, which prints the output to the screen after the power() operation is carried out on some variables.

RELATED TAGS

euphoria
functions
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring