Ticket #4867 (closed bug: fixed)
ghci displays negative floats incorrectly (was: Incorrect result from trig functions)
| Reported by: | gwright | Owned by: | gwright |
|---|---|---|---|
| Priority: | high | Milestone: | 7.0.2 |
| Component: | GHCi | Version: | 7.0.1 |
| Keywords: | Cc: | william.knop.nospam@…, arsenm2@…, pho@… | |
| Operating System: | MacOS X | Architecture: | x86_64 (amd64) |
| Type of failure: | Incorrect result at runtime | Difficulty: | |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
Trigonometric functions give the wrong answer in some cases. I have verified this bug on ghc-7.0.1 and ghc-7.0.1-rc1 on OS X 10.6 64 bit. (The bug may be limited to 64 bit platforms; I've not been able to reproduce it on ghc-6.10.4/OS X 10.5/32 bit.)
Here's an example (ghc-7.0.2-rc1, OS X 10.6, 64 bit):
plumbbob-franklin> inplace/bin/ghc-stage2 --interactive GHCi, version 7.0.1.20101221: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude> tan (0.5 * pi + 0.01) -4.563974029425858e214 Prelude> tan (0.5 * pi - 0.01) 99.99666664444354 Prelude>
The first result (tan (0.5 * pi + 0.01)) is wrong. The correct answer is close to -100.0. The sin and cos functions also give incorrect answers in some cases, e.g.,
Prelude> cos (3.0 * pi) -3.666940035476786e76
At first glance, the bug seems related to the normalization of the argument (i.e., mapping the argument to the range (-pi/2, pi/2)).
This is a nasty one. It ought to be fixed before 7.0.2 goes out.

