You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- TODO: this version should also work for NHC and Hugs, I think...
165
-
-- HACK: we should be able to just unsafeCoerce the functions themselves, instead of coercing the inputs and the outputs; but, GHC 7.10 seems to get confused about trying to coerce the index types too... To fix this we give explicit signatures, as below, but this requires both ScopedTypeVariables and InstanceSigs; and I'm not sure when InstanceSigs was introduced.
165
+
-- HACK: we should be able to just unsafeCoerce the functions
166
+
-- themselves, instead of coercing the inputs and the outputs; but,
167
+
-- GHC 7.10 seems to get confused about trying to coerce the index
168
+
-- types too... To fix this we give explicit signatures, as below,
169
+
-- but this requires both ScopedTypeVariables and InstanceSigs; and
170
+
-- I'm not sure when InstanceSigs was introduced.
166
171
167
172
instanceIArrayUArrayLogFloatwhere
168
173
{-# INLINE bounds #-}
@@ -606,12 +611,17 @@ product = kahan 0 0
606
611
where
607
612
kahan t c _ | t `seq` c `seq`False=undefined
608
613
kahan t _ []=LogFloat t
609
-
kahan t c (LogFloat x : xs) =
610
-
-- Beware this getting incorrectly optimized away by constant folding!
611
-
let y = x - c
612
-
t' = t + y
613
-
c' = (t' - t) - y
614
-
in kahan t' c' xs
614
+
kahan t c (LogFloat x : xs)
615
+
-- Avoid NaN when there's a negInfty in the list. N.B.,
616
+
-- this causes zero to annihilate infinity.
617
+
| x == negativeInfinity =LogFloat negativeInfinity
618
+
|otherwise=
619
+
-- Beware this getting incorrectly optimized away by
620
+
-- constant folding!
621
+
let y = x - c
622
+
t' = t + y
623
+
c' = (t' - t) - y
624
+
in kahan t' c' xs
615
625
616
626
-- This version *completely* eliminates rounding errors and loss
617
627
-- of significance due to catastrophic cancellation during summation.
0 commit comments