Commits

Aleksey Khudyakov committed bb34529

Optmize variance

  • Participants
  • Parent commits 31f9742

Comments (0)

Files changed (1)

Data/Monoid/Statistics/Numeric.hs

     where
       na = fromIntegral n1
       nb = fromIntegral n2
-      nom = (ta * nb - tb * na)^2
+      nom = sqr (ta * nb - tb * na)
       sumsq
         | n1 == 0 || n2 == 0 = sa + sb  -- because either sa or sb should be 0
         | otherwise          = sa + sb + nom / ((na + nb) * na * nb)
   toDouble = fromIntegral
   {-# INLINE toDouble #-}
 
- 
+ 
+sqr :: Double -> Double
+sqr x = x * x
+{-# INLINE sqr #-}