lib: Replace more instances of fromIntegral with safer versions.
This commit is contained in:
		
							parent
							
								
									ca2e55c954
								
							
						
					
					
						commit
						ba59fed6b2
					
				@ -105,7 +105,7 @@ splitPosting acct dates p@Posting{paccount,pamount}
 | 
			
		||||
        [d]        -> (d, [])
 | 
			
		||||
        []         -> error' "splitPosting ran out of dates, should not happen (maybe sort your transactions by date)"
 | 
			
		||||
    days = initSafe [start..end]
 | 
			
		||||
    amt  = (fromIntegral $ length days) `divideMixedAmount` pamount
 | 
			
		||||
    amt  = (genericLength days) `divideMixedAmount` pamount
 | 
			
		||||
    -- give one of the postings an exact balancing amount to ensure the transaction is balanced
 | 
			
		||||
    -- lastamt = pamount - ptrace (amt `multiplyMixedAmount` (fromIntegral $ length days))
 | 
			
		||||
    lastamt = missingmixedamt
 | 
			
		||||
 | 
			
		||||
@ -411,8 +411,8 @@ showamountquantity :: Amount -> String
 | 
			
		||||
showamountquantity Amount{aquantity=q, astyle=AmountStyle{asprecision=p, asdecimalpoint=mdec, asdigitgroups=mgrps}} =
 | 
			
		||||
    punctuatenumber (fromMaybe '.' mdec) mgrps qstr
 | 
			
		||||
    where
 | 
			
		||||
      -- isint n = fromIntegral (round n) == n
 | 
			
		||||
      qstr -- p == maxprecision && isint q = printf "%d" (round q::Integer)
 | 
			
		||||
      -- isint n = round n == n
 | 
			
		||||
      qstr  -- p == maxprecision && isint q = printf "%d" (round q::Integer)
 | 
			
		||||
        | p == maxprecisionwithpoint = show q
 | 
			
		||||
        | p == maxprecision          = chopdotzero $ show q
 | 
			
		||||
        | otherwise                  = show $ roundTo p q
 | 
			
		||||
 | 
			
		||||
@ -241,14 +241,13 @@ runErroringJournalParser p t =
 | 
			
		||||
rejp = runErroringJournalParser
 | 
			
		||||
 | 
			
		||||
genericSourcePos :: SourcePos -> GenericSourcePos
 | 
			
		||||
genericSourcePos p = GenericSourcePos (sourceName p) (fromIntegral . unPos $ sourceLine p) (fromIntegral . unPos $ sourceColumn p)
 | 
			
		||||
genericSourcePos p = GenericSourcePos (sourceName p) (unPos $ sourceLine p) (unPos $ sourceColumn p)
 | 
			
		||||
 | 
			
		||||
-- | Construct a generic start & end line parse position from start and end megaparsec SourcePos's.
 | 
			
		||||
journalSourcePos :: SourcePos -> SourcePos -> GenericSourcePos
 | 
			
		||||
journalSourcePos p p' = JournalSourcePos (sourceName p) (fromIntegral . unPos $ sourceLine p, fromIntegral $ line')
 | 
			
		||||
    where line'
 | 
			
		||||
            | (unPos $ sourceColumn p') == 1 = unPos (sourceLine p') - 1
 | 
			
		||||
            | otherwise = unPos $ sourceLine p' -- might be at end of file withat last new-line
 | 
			
		||||
journalSourcePos p p' = JournalSourcePos (sourceName p) (unPos $ sourceLine p, line')
 | 
			
		||||
    where line' | (unPos $ sourceColumn p') == 1 = unPos (sourceLine p') - 1
 | 
			
		||||
                | otherwise = unPos $ sourceLine p' -- might be at end of file withat last new-line
 | 
			
		||||
 | 
			
		||||
-- | Given a parser to ParsedJournal, input options, file path and
 | 
			
		||||
-- content: run the parser on the content, and finalise the result to
 | 
			
		||||
 | 
			
		||||
@ -404,9 +404,9 @@ textWidth s = maximum $ map (T.foldr (\a b -> charWidth a + b) 0) $ T.lines s
 | 
			
		||||
 | 
			
		||||
-- | Read a decimal number from a Text. Assumes the input consists only of digit
 | 
			
		||||
-- characters.
 | 
			
		||||
readDecimal :: Integral a => Text -> a
 | 
			
		||||
readDecimal :: Text -> Integer
 | 
			
		||||
readDecimal = foldl' step 0 . T.unpack
 | 
			
		||||
  where step a c = a * 10 + fromIntegral (digitToInt c)
 | 
			
		||||
  where step a c = a * 10 + toInteger (digitToInt c)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
tests_Text = tests "Text" [
 | 
			
		||||
 | 
			
		||||
@ -360,7 +360,7 @@ rsHandle ui@UIState{
 | 
			
		||||
              let
 | 
			
		||||
                ts = map rsItemTransaction $ V.toList $ nonblanks
 | 
			
		||||
                numberedts = zip [1..] ts
 | 
			
		||||
                i = fromIntegral $ maybe 0 (+1) $ elemIndex t ts -- XXX
 | 
			
		||||
                i = maybe 0 (toInteger . (+1)) $ elemIndex t ts -- XXX
 | 
			
		||||
              in
 | 
			
		||||
                continue $ screenEnter d transactionScreen{tsTransaction=(i,t)
 | 
			
		||||
                                                          ,tsTransactions=numberedts
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user