3

Python's builtin pow function pow(-1, 0.5) and exponentitaion function (-1)**0.5 return non-zero real value as 6.123233995736766e-17.

Why is the real part of the complex number not absolute zero?

Preetkaran Singh
  • 502
  • 5
  • 19
  • is it ' the error constant ' – Preetkaran Singh Jul 19 '20 at 20:27
  • Might be useful: [How to round up a complex number?](https://stackoverflow.com/q/25820322/4518341) – wjandrea Jul 19 '20 at 20:27
  • @wjandrea I want to understand how the error in float computation is `6.123e-17`, as I'm implementing inv trigo functions, and this specific value is used as a lower bound – Preetkaran Singh Jul 19 '20 at 20:35
  • Why not use a complex type with arbitrary precision in the first place? Check out [Decimal module and complex numbers in Python](https://stackoverflow.com/q/44500275/4518341). For example `from mpmath import *; mpf(-1) ** 0.5` -> `mpc(real='0.0', imag='1.0')` – wjandrea Jul 19 '20 at 20:48
  • 3
    This comment was incorrectly closed as a duplicate of [that overused and infamous question](https://stackoverflow.com/questions/588004/is-floating-point-math-broken). The behavior asked about is **not** a necessity of floating-point behavior: −1, 0.5, and pow(−1, 0.5) are all exactly representable in ordinary floating-point formats. The problem is caused by how `pow` is implemented. – Eric Postpischil Jul 20 '20 at 00:17
  • @PreetkaranSingh: This doesn't answer your question, but if you want a complex square root, I'd recommend using `cmath.sqrt` in preference to `pow(z, 0.5)` or `z**0.5`. – Mark Dickinson Jul 20 '20 at 14:02

0 Answers0