On Sun, Jul 05, 2015 at 12:11:15PM -0700, Linus Torvalds wrote: > On Sun, Jul 5, 2015 at 11:56 AM, Dirk Hohndel <[email protected]> wrote: > > static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, int > > roundto) { > > depth_t depth; > > depth.mm = ((po2_limit.mbar * 1000 / get_o2(mix) * 10 - 10000) / > > roundto) * roundto; > > return depth; > > } > > > > So all we need to do is adjust this function to add (roundto - 1) to the > > enumerator before deviding by roundto, correct? > > Ugh. I think it would be better to write it more readably first. > That's a particularly unreadable line of noise.
Well, Robert wrote it, now he can fix it. > At the very least, split it up, and do the rounding separately. And > no, you shouldn't add "roundto-1" unless you always want to round > _up_. I'd assume you'd want to round-to-nearest, and add "roundto/2" > instead. Umm. Err. Yeah. That's what I meant to say... > Or just use floating point and "rint()". > > So something like > > depth.mm = po2_limit.mbar * 1000 / get_o2(mix) * 10 - 10000; > depth.mm = rint(depth.mm / (double) roundto) * roundto; That ceratinly would be much more readable. > Which just leaves the initial actual depth math, which is also qutie > debatably wrong. > > Looking at that first line, it truncates the depth to cm because it > does that "*10" last, after having done a truncating divide. So it > does the math in steps of 10mm, which looks bogus too. Of course, that > math is just hardcoding the "one bar per 10m of water", which might be > a bit questionable to begin with. But I guess that's how people > calculate PO2 limits, so.. And of course you could just send a patch... you used to do that :-) /D _______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
