Ticket #4228 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

atanh (-1) returns NaN instead of -Infinity

Reported by: sbroadhead Owned by:
Priority: normal Milestone: 7.0.1
Component: Prelude Version: 6.12.1
Keywords: Cc: ghc@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

According to the man page for libc's atanh:

If x is +1 or -1, a pole error occurs, and the functions return HUGE_VAL, HUGE_VALF, or HUGE_VALL, respectively, with the mathematically correct sign.

atanh 1 correctly returns Infinity, but atanh (-1) returns NaN instead of -Infinity. A C program compiled on the same system gives the correct result.

Attachments

4228.patch Download (44.6 KB) - added by norriscm 3 years ago.
FIX #4228 (use alternate formula for atanh)

Change History

Changed 3 years ago by igloo

  • os changed from MacOS X to Unknown/Multiple
  • architecture changed from x86 to Unknown/Multiple
  • milestone set to 6.14.1

Since the beginning of time:

Thu Jun 28 15:15:04 BST 2001  simonmar
  * [project @ 2001-06-28 14:15:04 by simonmar]
  First cut of the Haskell Core Libraries

we've had:

asinh x = log (x + sqrt (1.0+x*x))
acosh x = log (x + (x+1.0) * sqrt ((x-1.0)/(x+1.0)))
atanh x = log ((x+1.0) / sqrt (1.0-x*x))

for Double, Float and Complex a.

Changed 3 years ago by norriscm

FIX #4228 (use alternate formula for atanh)

Changed 3 years ago by norriscm

  • cc ghc@… added
  • status changed from new to patch

By using a different (but mathematically equivalent) formula for atanh, we can get the desired behavior without explicitly handling the branch cuts:

atanh x = 0.5 * log ((1.0+x) / (1.0-x))

This definition gives atanh 1 == Infinity and atanh -1 == -Infinity. The attached patch makes the changes in GHC.Float and Data.Complex for the Float, Double, and Complex a instances.

Changed 3 years ago by igloo

  • status changed from patch to closed
  • resolution set to fixed

Patch applied, thanks.

Note: See TracTickets for help on using tickets.