Fwd: add instance PrintfArg Ratio
---------- Forwarded message --------- 보낸사람: Dannyu NDos <ndospark320@gmail.com> Date: 2020년 2월 9일 (일) 오후 3:14 Subject: Re: add instance PrintfArg Ratio To: Henning Thielemann <lemming@henning-thielemann.de> Bugfix: instance (Integral a, PrintfArg a) => PrintfArg (Ratio a) where formatArg x f@(FieldFormat w p a s l _ c) = if elem c "gGv" then let d = " % " ++ formatArg (denominator x) (FieldFormat Nothing Nothing Nothing s l "" 'd') "" (w',a') = case a of Just LeftAdjust -> (Nothing, Nothing) _ -> (fmap (subtract (length d)) w, a) n = formatArg (numerator x) (f {fmtWidth = w', fmtAdjust = a', fmtChar = 'd'}) "" in formatArg (n ++ d) (f {fmtPrecision = Nothing, fmtChar = 's'}) else if elem c "doxXb" then formatArg (round x :: Integer) f else case p of Nothing -> error "Text.Printf.formatArg: precision not given" Just p' -> if p' <= 0 then formatArg x (f {fmtPrecision = Nothing, fmtChar = 'd'}) else if elem c "fF" then let a' = case a of Just LeftAdjust -> Nothing _ -> a digits = formatArg (truncate (x * 10 ^ p') :: Integer) (f {fmtPrecision = Nothing, fmtAdjust = a', fmtChar = 'd'}) "" (n,sig) = splitAt (length digits - p') digits in formatArg (n ++ '.' : sig) (f {fmtPrecision = Nothing, fmtChar = 's'}) else if elem c "eE" then let (q,e) = log10 x sig = c : show e (w',a') = case a of Just LeftAdjust -> (Nothing, Nothing) _ -> (fmap (subtract (length sig)) w, a) fp = formatArg q (f {fmtWidth = w', fmtAdjust = a', fmtChar = 'f'}) "" in formatArg (fp ++ sig) (f {fmtPrecision = Nothing, fmtChar = 's'}) else error "Text.Printf.formatArg: bad format character" where goF _ 0 = "" goF x p = case compare x 0 of LT -> '-' : goF (negate x) p EQ -> "0" GT -> if 1 == p then show (round (10 * x) :: Integer) else let x10 = 10 * x n = truncate x10 in show n ++ goF (x10 - fromIntegral n) (p - 1) log10 x | x < 1 = let (q,e) = log10 (x * 10) in (q, e - 1) | 10 <= x = let (q,e) = log10 (x / 10) in (q, e + 1) | otherwise = (x, 0)
Bugfix: use round instead of truncate.
The libraries@haskell.org mailing list is not a forum to develop and debug haskell functions. Please refrain from further updates on your development process. Once the proposal is mature and secured by a testsuite it makes sense to subject it again to discussion on this mailing list. Thanks, Andreas On 2020-02-09 11:20, Dannyu NDos wrote:
Also goF is no longer needed.
2020년 2월 9일 (일) 오후 7:19, Dannyu NDos <ndospark320@gmail.com <mailto:ndospark320@gmail.com>>님이 작성:
Bugfix: use round instead of truncate.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Hello Andreas, I’m also part of this mailing list, and while I agree with what you just said, I believe the tone of your message was slightly unfriendly (though still polite). I hope you do not mind this comment – as you said, there are certainly more appropriate venues for the contents of this email thread. However, the best part about our community is, I think, (still) the kind way in which we treat each other. Cheers ________________________________ De: Libraries <libraries-bounces@haskell.org> em nome de Andreas Abel <andreas.abel@ifi.lmu.de> Enviado: Monday, February 10, 2020 6:21:57 PM Para: libraries@haskell.org <libraries@haskell.org> Assunto: Re: add instance PrintfArg Ratio The libraries@haskell.org mailing list is not a forum to develop and debug haskell functions. Please refrain from further updates on your development process. Once the proposal is mature and secured by a testsuite it makes sense to subject it again to discussion on this mailing list. Thanks, Andreas On 2020-02-09 11:20, Dannyu NDos wrote:
Also goF is no longer needed.
2020년 2월 9일 (일) 오후 7:19, Dannyu NDos <ndospark320@gmail.com <mailto:ndospark320@gmail.com>>님이 작성:
Bugfix: use round instead of truncate.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
participants (3)
-
Alexandre Rodrigues Baldé -
Andreas Abel -
Dannyu NDos