-
-
Save mithrandi/bddb422c9b751d104f85fd926d896a95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
showRational :: Int64 -> Rational -> Builder | |
showRational len n = sign <> TS.showb d <> "." <> decs | |
where | |
sign = | |
if num < 0 | |
then "-" | |
else mempty | |
decs = fromLazyText . TL.take len . toLazyText $ go next | |
(d, next) = abs num `quotRem` den | |
go 0 = mempty | |
go x = | |
let (d', next') = (10 * x) `quotRem` den | |
in TS.showb d' <> go next' | |
num = numerator n | |
den = denominator n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment