diff --git a/CHANGELOG.md b/CHANGELOG.md index c825f412..7601500e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +1.0.1.3 (2016-09) +----------------- +* Fixed an issue with applying metric prefixes to units with non-rational conversion factors. + 1.0.1.2 (2016-05) ----------------- * Support for GHC 8.0.1-rc4, avoiding GHC Trac issue 12026. diff --git a/dimensional.cabal b/dimensional.cabal index 8758d5c5..0372377d 100644 --- a/dimensional.cabal +++ b/dimensional.cabal @@ -1,5 +1,5 @@ name: dimensional -version: 1.0.1.2 +version: 1.0.1.3 license: BSD3 license-file: LICENSE copyright: Bjorn Buckwalter 2006-2015 diff --git a/src/Numeric/Units/Dimensional.hs b/src/Numeric/Units/Dimensional.hs index 88d0acb6..7877e524 100644 --- a/src/Numeric/Units/Dimensional.hs +++ b/src/Numeric/Units/Dimensional.hs @@ -665,8 +665,11 @@ we provide a means for converting from type-level dimensions to term-level dimen -- Supplying negative defining quantities is allowed and handled gracefully, but is discouraged -- on the grounds that it may be unexpected by other readers. mkUnitR :: Floating a => UnitName m -> ExactPi -> Unit m1 d a -> Unit m d a -mkUnitR n s' (Unit _ s x) | isExactZero s = error "Supplying zero as a conversion factor is not valid." - | otherwise = Unit n (s' Prelude.* s) (approximateValue s' Prelude.* x) +mkUnitR n s (Unit _ e _) | isExactZero s = error "Supplying zero as a conversion factor is not valid." + | otherwise = Unit n e' x' + where + e' = s Prelude.* e + x' = approximateValue e' -- | Forms a new atomic 'Unit' by specifying its 'UnitName' and its definition as a multiple of another 'Unit'. -- @@ -675,11 +678,12 @@ mkUnitR n s' (Unit _ s x) | isExactZero s = error "Supplying zero as a conversio -- -- For more information see 'mkUnitR'. mkUnitQ :: Fractional a => UnitName m -> Rational -> Unit m1 d a -> Unit m d a -mkUnitQ n s' (Unit _ s _) | s' == 0 = error "Supplying zero as a conversion factor is not valid." - | Just q <- toExactRational s'' = Unit n s'' (fromRational q) - | otherwise = error "The resulting conversion factor is not an exact rational." +mkUnitQ n s (Unit _ e x) | s == 0 = error "Supplying zero as a conversion factor is not valid." + | Just x'' <- toExactRational e' = Unit n e' (fromRational x'') + | otherwise = Unit n e' x' where - s'' = fromRational s' Prelude.* s + e' = fromRational s Prelude.* e + x' = fromRational s Prelude.* x -- | Forms a new atomic 'Unit' by specifying its 'UnitName' and its definition as a multiple of another 'Unit'. -- @@ -688,8 +692,9 @@ mkUnitQ n s' (Unit _ s _) | s' == 0 = error "Supplying zer -- -- For more information see 'mkUnitR'. mkUnitZ :: Num a => UnitName m -> Integer -> Unit m1 d a -> Unit m d a -mkUnitZ n s' (Unit _ s _) | s' == 0 = error "Supplying zero as a conversion factor is not valid." - | Just z <- toExactInteger s'' = Unit n s'' (fromInteger z) - | otherwise = error "The resulting conversion factor is not an exact integer." +mkUnitZ n s (Unit _ e x) | s == 0 = error "Supplying zero as a conversion factor is not valid." + | Just x'' <- toExactInteger e' = Unit n e' (fromInteger x'') + | otherwise = Unit n e' x' where - s'' = fromInteger s' Prelude.* s + e' = fromInteger s Prelude.* e + x' = fromInteger s Prelude.* x