[Haskell-cafe] Default implementation of Floating (**)

Henning Thielemann lemming at henning-thielemann.de
Wed May 19 14:58:38 UTC 2021

On Wed, 19 May 2021, Fabrício Olivetti de França wrote:

> I was using Numeric.Interval in my code and found an issue with the
> (**) operator, if the interval contains negative values, it will
> return a wrong result (as reported in this open issue
> https://github.com/ekmett/intervals/issues/50).

If you need negative bases you must use (^^) instead of (**).

> Investigating the source of this problem, I found that it uses the
> default implementation of (**) from base defined as x ** y = exp (log
> x * y).

This default implementation is correct. Power (**) is only defined for 
positive reals like in mathematics.

The example in the GitHub issue will not work if your interval is slightly 
larger than just the point 2. Think of the interval x=[-2.1,-1.9]. What 
should x**x be? In contrast to that x^^(-2) would be fine.

More information about the Haskell-Cafe mailing list