base: Update acosh to handle -1::Complex
authorAlex Bradley <a.s.bradley1996@gmail.com>
Mon, 4 Sep 2017 12:08:46 +0000 (08:08 -0400)
committerBen Gamari <ben@smart-cactus.org>
Tue, 5 Sep 2017 11:20:00 +0000 (07:20 -0400)
Summary: Fixes #8532

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #8532

Differential Revision: https://phabricator.haskell.org/D3916

libraries/base/Data/Complex.hs
testsuite/tests/numeric/should_run/all.T
testsuite/tests/numeric/should_run/numrun016.hs [new file with mode: 0644]
testsuite/tests/numeric/should_run/numrun016.stdout [new file with mode: 0644]

index dd3e0ec..e4ed4e8 100644 (file)
@@ -197,7 +197,8 @@ instance  (RealFloat a) => Floating (Complex a) where
                       where (x':+y') = log (((1-y):+x) / sqrt (1+z*z))
 
     asinh z        =  log (z + sqrt (1+z*z))
-    acosh z        =  log (z + (z+1) * sqrt ((z-1)/(z+1)))
+    -- Take care to allow (-1)::Complex, fixing #8532
+    acosh z        =  log (z + (sqrt $ z+1) * (sqrt $ z-1))
     atanh z        =  0.5 * log ((1.0+z) / (1.0-z))
 
     log1p x@(a :+ b)
index 2d2353b..fd9c05f 100644 (file)
@@ -34,6 +34,7 @@ test('numrun012', normal, compile_and_run, [''])
 test('numrun013', normal, compile_and_run, [''])
 test('numrun014', normal, compile_and_run, [''])
 test('numrun015', normal, compile_and_run, [''])
+test('numrun016', normal, compile_and_run, [''])
 test('arith016', normal, compile_and_run, [''])
 test('arith017', normal, compile_and_run, [''])
 test('arith018', normal, compile_and_run, [''])
diff --git a/testsuite/tests/numeric/should_run/numrun016.hs b/testsuite/tests/numeric/should_run/numrun016.hs
new file mode 100644 (file)
index 0000000..c45e322
--- /dev/null
@@ -0,0 +1,8 @@
+-- test for trac #8532
+
+import Data.Complex
+
+main :: IO ()
+main = do
+    print $ acosh ((-1)::Complex Double)
+    print $ acosh ((-1)::Complex Float)
diff --git a/testsuite/tests/numeric/should_run/numrun016.stdout b/testsuite/tests/numeric/should_run/numrun016.stdout
new file mode 100644 (file)
index 0000000..25676f7
--- /dev/null
@@ -0,0 +1,2 @@
+0.0 :+ 3.141592653589793
+0.0 :+ 3.1415927
\ No newline at end of file