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