Skip to content

Commit

Permalink
gauche.time - Avoid error when rate yields +inf.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shirok committed Apr 24, 2017
1 parent 6c5854d commit a45cb3a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/gauche/time.scm
Expand Up @@ -51,9 +51,11 @@

;; TODO: Drop these once we support sane formatting of flonums in format.
(define (format-flonum val mincol digs)
(let* ([scale (expt 10 digs)]
[n (round->exact (* val scale))])
(format "~vd.~v,'0d" mincol (div n scale) digs (mod n scale))))
(if (finite? val)
(let* ([scale (expt 10 digs)]
[n (round->exact (* val scale))])
(format "~vd.~v,'0d" mincol (div n scale) digs (mod n scale)))
(format "~a" val)))

(define (format-delta-time delta) (format-flonum delta 3 3))

Expand Down Expand Up @@ -209,7 +211,10 @@
ks rs ps us ss cs (map (cut ref <> 'count) ts))
;; matrix
(let1 mat (map (^y (map (^x (if (eq? x y) "--" (ratio y x))) ts)) ts)
(receive (Cs Cw) (fmt+w (.$ x->string x->integer rate) ts)
(receive (Cs Cw) (fmt+w (^t (if (finite? (rate t))
($ x->string $ x->integer $ rate t)
($ x->string $ rate t)))
ts)
(let1 Cw (max (+ Cw 2) 4) ; minimum width for "Rate"
(format #t "\n ~v@a ~v@a" kw "" Cw "Rate")
(let1 col-widths (map (pa$ apply max)
Expand Down

0 comments on commit a45cb3a

Please sign in to comment.