Skip to main content

Timeline for Why is (-1.)^2. a complex number

Current License: CC BY-SA 3.0

6 events
when toggle format what by license comment
Jan 21, 2015 at 10:32 comment added Oleksandr R. N.B. result = SetPrecision[-1, $MachinePrecision]^SetPrecision[2, $MachinePrecision]; Log[2, 10^$MachinePrecision] - Log[2, 10^Accuracy@Im[result]] gives 3.05. But I don't know what to make of this; I am not sure if it is significance arithmetic telling us that we should have lost this much precision, or if we really have.
Jan 21, 2015 at 10:22 comment added Oleksandr R. +1 for Dan's comment explaining it (transcendental functions are not included in the IEEE754 specification, so >0.5 ULP error should be acceptable for them, even if technically the implementation of Power should not be done this way if we are following the standard), but I don't follow why arbitrary precision doesn't resolve the problem? SetPrecision[-1, $MachinePrecision]^SetPrecision[2, $MachinePrecision] gives an exactly rounded result; remove the $ and this is lost. The arbitrary-precision Log and Exp implementations seem more accurate than their machine-precision counterparts.
Jan 21, 2015 at 2:11 comment added Mr.Wizard @Oleksandr Thanks for the comment. By the way I believe I was mistaken regarding arbitrary precision and I revised my answer accordingly.
Jan 21, 2015 at 2:08 history edited Mr.Wizard CC BY-SA 3.0
added 670 characters in body
Jan 20, 2015 at 21:49 comment added Oleksandr R. I think the question is really: why is Mathematica's Power function less accurate than those in other languages? Here we have 1.1 ULP of error. Practically speaking we can say that the other languages follow IEEE754 (which requires exact rounding, so <0.5 ULP error in all operations), and Mathematica doesn't. Some justification of this is probably called for so long as Mathematica gives inferior results. But, interestingly, we do not have these problems as soon as you go to arbitrary precision.
Jan 13, 2015 at 22:58 history answered Mr.Wizard CC BY-SA 3.0