On 2019-01-19 15:00:20, Otto Moerbeek <[email protected]> wrote: > On Sat, Jan 19, 2019 at 09:30:12PM +0900, Bryan Linton wrote: > > > Hello tech@, > > > > I'd appreciate it if someone could review both this patch and my > > analysis. > > > > [...] > > > > ADDENDUM > > ________ > > > > I'm curious why iostat.c uses cur.dk_*[dn] directly whereas > > vmstat.c adds 0.5 to it. > > rsum += cur.dk_rbytes[dn] / etime; > > rsum is a double. When adding a double to a double, there's no > rounding or truncation going on. > > > vs. > > words = (cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) / 1024.0; > > putintmk((int)(words/etime + 0.5), DISKROW + 3, c, 5); > > ^^^^^^ > > When converting a double (or float) to an int, truncation happens. So > add 0.5 to turn it into rounding. >
Ah, OK. I get it now. > > Also, there are several casts in lines like > > putint((int)((float)cur.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5) > > > > I understand why the value would need to be cast to an (int), > > since putint() is expecting an int, but since etime is already a > > (double), wouldn't the C language's automatic type-promotion rules > > automatically promote everything to a (double) anyway? > > Those casts are indeed unneeded, > Thank you for taking the time to explain both of these! -- Bryan
