Ticket #4413 (new bug)

Opened 3 years ago

Last modified 9 months ago

(^^) is not correct for Double and Float

Reported by: daniel.is.fischer Owned by: tcsavage
Priority: low Milestone: 7.6.2
Component: libraries/base Version: 7.1
Keywords: Double, Float, exponentiation Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Consider

Prelude> 2 ^^ (-1024)
0.0
Prelude> 0.5 ^^ 1024
5.562684646268003e-309

The cause is

x ^^ n          =  if n >= 0 then x^n else recip (x^(negate n))

If we change it to

x ^^ n          =  if n >= 0 then x^n else ((recip x)^(negate n))

it'll do the right thing for Double and Float, and I don't know of any type where it would produce incorrect results.

Does it need a library proposal or can the change be made without?

Change History

Changed 3 years ago by igloo

I'm not sure I see why this is necessarily more correct in general.

Changed 3 years ago by daniel.is.fischer

It produces correct (in the sense of "if the real result of xn is a finite nonzero number, so is x ^^ n, and the value of x ^^ n differs only very little from each of the real value, x ** n and fromRational (toRational x ^^ n)") results for more inputs. When abs(x) > 1, n < 0 and x ^ (-n) gives Infinity, so x ^^ n yields 1/Infinity = 0, (1/x) ^ (-n) can, as in the example, yield a nonzero (subnormal) number.

Changed 3 years ago by igloo

  • milestone set to 7.2.1

Changed 16 months ago by igloo

  • priority changed from normal to low
  • milestone changed from 7.4.1 to 7.6.1

Changed 13 months ago by tcsavage

  • owner set to tcsavage

Changed 9 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.