lib: drop "double" build flag
This commit is contained in:
parent
ff09d60746
commit
ea383d88d6
@ -101,11 +101,7 @@ module Hledger.Data.Amount (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Char (isDigit)
|
import Data.Char (isDigit)
|
||||||
#ifdef DOUBLE
|
|
||||||
roundTo = flip const
|
|
||||||
#else
|
|
||||||
import Data.Decimal (roundTo)
|
import Data.Decimal (roundTo)
|
||||||
#endif
|
|
||||||
import Data.Function (on)
|
import Data.Function (on)
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Map (findWithDefault)
|
import Data.Map (findWithDefault)
|
||||||
@ -211,16 +207,8 @@ isZeroAmount a -- a==missingamt = False
|
|||||||
| otherwise = (null . filter (`elem` digits) . showAmountWithoutPriceOrCommodity) a
|
| otherwise = (null . filter (`elem` digits) . showAmountWithoutPriceOrCommodity) a
|
||||||
|
|
||||||
-- | Is this amount "really" zero, regardless of the display precision ?
|
-- | Is this amount "really" zero, regardless of the display precision ?
|
||||||
-- Since we are using floating point, for now just test to some high precision.
|
|
||||||
isReallyZeroAmount :: Amount -> Bool
|
isReallyZeroAmount :: Amount -> Bool
|
||||||
isReallyZeroAmount Amount{aquantity=q} = iszero q
|
isReallyZeroAmount Amount{aquantity=q} = q == 0
|
||||||
where
|
|
||||||
iszero =
|
|
||||||
#ifdef DOUBLE
|
|
||||||
null . filter (`elem` digits) . printf ("%."++show zeroprecision++"f") where zeroprecision = 8
|
|
||||||
#else
|
|
||||||
(==0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Get the string representation of an amount, based on its commodity's
|
-- | Get the string representation of an amount, based on its commodity's
|
||||||
-- display settings except using the specified precision.
|
-- display settings except using the specified precision.
|
||||||
@ -292,15 +280,9 @@ showamountquantity Amount{aquantity=q, astyle=AmountStyle{asprecision=p, asdecim
|
|||||||
where
|
where
|
||||||
-- isint n = fromIntegral (round n) == n
|
-- isint n = fromIntegral (round n) == n
|
||||||
qstr -- p == maxprecision && isint q = printf "%d" (round q::Integer)
|
qstr -- p == maxprecision && isint q = printf "%d" (round q::Integer)
|
||||||
#ifdef DOUBLE
|
|
||||||
| p == maxprecisionwithpoint = printf "%f" q
|
|
||||||
| p == maxprecision = chopdotzero $ printf "%f" q
|
|
||||||
| otherwise = printf ("%."++show p++"f") q
|
|
||||||
#else
|
|
||||||
| p == maxprecisionwithpoint = show q
|
| p == maxprecisionwithpoint = show q
|
||||||
| p == maxprecision = chopdotzero $ show q
|
| p == maxprecision = chopdotzero $ show q
|
||||||
| otherwise = show $ roundTo (fromIntegral p) q
|
| otherwise = show $ roundTo (fromIntegral p) q
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Replace a number string's decimal point with the specified character,
|
-- | Replace a number string's decimal point with the specified character,
|
||||||
-- and add the specified digit group separators. The last digit group will
|
-- and add the specified digit group separators. The last digit group will
|
||||||
|
|||||||
@ -24,10 +24,8 @@ import GHC.Generics (Generic)
|
|||||||
import Control.DeepSeq (NFData)
|
import Control.DeepSeq (NFData)
|
||||||
import Control.Monad.Except (ExceptT)
|
import Control.Monad.Except (ExceptT)
|
||||||
import Data.Data
|
import Data.Data
|
||||||
#ifndef DOUBLE
|
|
||||||
import Data.Decimal
|
import Data.Decimal
|
||||||
import Text.Blaze (ToMarkup(..))
|
import Text.Blaze (ToMarkup(..))
|
||||||
#endif
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Data.Time.LocalTime
|
import Data.Time.LocalTime
|
||||||
@ -64,13 +62,7 @@ data Side = L | R deriving (Eq,Show,Read,Ord,Typeable,Data,Generic)
|
|||||||
|
|
||||||
instance NFData Side
|
instance NFData Side
|
||||||
|
|
||||||
-- | The basic numeric type used in amounts. Different implementations
|
-- | The basic numeric type used in amounts.
|
||||||
-- can be selected via cabal flag for testing and benchmarking purposes.
|
|
||||||
numberRepresentation :: String
|
|
||||||
#ifdef DOUBLE
|
|
||||||
type Quantity = Double
|
|
||||||
numberRepresentation = "Double"
|
|
||||||
#else
|
|
||||||
type Quantity = Decimal
|
type Quantity = Decimal
|
||||||
deriving instance Data (Quantity)
|
deriving instance Data (Quantity)
|
||||||
-- The following is for hledger-web, and requires blaze-markup.
|
-- The following is for hledger-web, and requires blaze-markup.
|
||||||
@ -78,8 +70,6 @@ deriving instance Data (Quantity)
|
|||||||
instance ToMarkup (Quantity)
|
instance ToMarkup (Quantity)
|
||||||
where
|
where
|
||||||
toMarkup = toMarkup . show
|
toMarkup = toMarkup . show
|
||||||
numberRepresentation = "Decimal"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | An amount's price (none, per unit, or total) in another commodity.
|
-- | An amount's price (none, per unit, or total) in another commodity.
|
||||||
-- Note the price should be a positive number, although this is not enforced.
|
-- Note the price should be a positive number, although this is not enforced.
|
||||||
|
|||||||
@ -61,8 +61,6 @@ flag old-locale
|
|||||||
if true then depend on time < 1.5 together with old-locale.
|
if true then depend on time < 1.5 together with old-locale.
|
||||||
|
|
||||||
library
|
library
|
||||||
if flag(double)
|
|
||||||
cpp-options: -DDOUBLE
|
|
||||||
ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans
|
ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.3 && < 5
|
base >= 4.3 && < 5
|
||||||
|
|||||||
@ -14,7 +14,6 @@ where
|
|||||||
import System.Info (os, arch)
|
import System.Info (os, arch)
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
||||||
import Hledger.Data.Types (numberRepresentation)
|
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ version = VERSION
|
|||||||
version = "dev build"
|
version = "dev build"
|
||||||
#endif
|
#endif
|
||||||
prognameandversion = progname ++ " " ++ version
|
prognameandversion = progname ++ " " ++ version
|
||||||
prognameanddetailedversion = printf "%s %s, using %s" progname version numberRepresentation
|
prognameanddetailedversion = printf "%s %s" progname version
|
||||||
|
|
||||||
-- developer build version strings include PATCHLEVEL (number of
|
-- developer build version strings include PATCHLEVEL (number of
|
||||||
-- patches since the last tag). If defined, it must be a number.
|
-- patches since the last tag). If defined, it must be a number.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user