Powers, remainders and functions (Calculator)

Add ^ (power, binds tighter than and is right-associative: 2 ^ 3 ^ 2 = 512), % (remainder, same level as ), and sqrt(x) and abs(x). sqrt of a negative, or a result that is infinite, prints Error: math domain; x % 0 is a division by zero.

Input: As before.

Output: As before.

Difficulty: Medium. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Parse power below unary minus on the right side so 2 ^ -1 works, and above it on the left so -2 ^ 2 = -4.

More Calculator practice