Opened 6 years ago
Closed 5 years ago
#4228 closed bug (fixed)
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 | Test Case: | |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Rev(s): | ||
Wiki Page: |
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 (1)
Change History (4)
comment:1 Changed 6 years ago by igloo
- Architecture changed from x86 to Unknown/Multiple
- Milestone set to 6.14.1
- Operating System changed from MacOS X to Unknown/Multiple
comment:2 Changed 5 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.
comment:3 Changed 5 years ago by igloo
- Resolution set to fixed
- Status changed from patch to closed
Patch applied, thanks.
Since the beginning of time:
we've had:
for Double, Float and Complex a.