Permalink
Browse files

prevent information loss (nonzero tower truncation) in toRational

  • Loading branch information...
1 parent 27ecc8e commit cd2965a6741291570930e4bf6e9f8f9ab64ccadd Barak A. Pearlmutter committed May 21, 2009
Showing with 5 additions and 1 deletion.
  1. +5 −1 Numeric/FAD.hs
View
@@ -456,7 +456,11 @@ instance RealFrac a => RealFrac (Tower tag a) where
floor = liftA1disc floor
instance Real a => Real (Tower tag a) where
- toRational = liftA1disc toRational
+ -- this would be a bug, as it would discard the tower:
+ -- toRational = liftA1disc toRational
+ toRational (Tower []) = 0
+ toRational (Tower [x0]) = toRational x0
+ toRational _ = error "toRational of Dual number with tower"
instance (Eq a, Num a) => Eq (Tower tag a) where
(==) = liftA2disc (==)

0 comments on commit cd2965a

Please sign in to comment.