-1

I am trying to raise -48.08 to the power of 0.2 which should equal -2.17. However when trying to calculate this in python, every way I've tried, I cannot seem to arrive at that number.

Here are my attempted solutions:

math.pow(-48.08 , 0.2)

which gives the following error:

ValueError: math domain error

Another solution attempted was:

-48.08 ** 0.2

Which gives a complex number 197498009.35948756-143490702.9960685j

Does anyone know a way in which I could achieve this?

Thanks

gerardcslabs
  • 213
  • 1
  • 3
  • 9
  • 1
    `(-48.08) ** 0.2` does not equal -2.17, but `-(48.08 ** 0.2)` does. Which of the two do you want? – Nils Werner Jan 14 '21 at 10:10
  • "Which gives a complex number `197498009.35948756-143490702.9960685j`" Err. Are you _sure_ about that? Assuming that you meant `(-48.08) ** 0.2` rather than `-48.08 ** 0.2` (which is `-2.1696660420701677`), that complex result is _way_ too large. If you're really getting that result, that looks like a bug somewhere. – Mark Dickinson Jan 14 '21 at 13:22
  • @NilsWerner I just did they both give the exact same on my calculator – gerardcslabs Jan 14 '21 at 13:32
  • @MarkDickinson I'm literally only using those numbers and doing as that, I get that complex number. – gerardcslabs Jan 14 '21 at 13:34
  • @gerardcslabs: Then something somewhere is very wrong. Can you post _exactly_ the code that you ran, and describe how you ran it? What version of Python are you using, and where did you get it from? Is this definitely CPython? Or some other flavour of Python? What platform? Are you running the code in a script, or directly in the Python interpreter? – Mark Dickinson Jan 14 '21 at 13:51
  • @MarkDickinson thanks Mark but not to worry! The bottom solution seems to work for some reason. – gerardcslabs Jan 14 '21 at 15:09

2 Answers2

1

Your second approach should work not sure if you are doing it correctly. Try this:

import math
-48.08 ** 0.2

Output:
-2.1696660420701677

However a point to note here is that ** operator binds more tightly than the - operator in Python. If you want to override that, you'd use parentheses.

Refer this and this thread for complete details on the operator precedence

think-maths
  • 917
  • 2
  • 10
  • 28
0
import math

print(-(math.pow(48.08, 0.2)))

Maybe can help you? In math (in python) you can't do that