From 23baf20f569f1f34ab4efa68996f24c3ad49fe05 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 12 Feb 2014 14:19:53 -0800 Subject: Use "rint()" instead of rounding manually with "+ 0.5" rint() is "round to nearest integer", and does a better job than +0.5 (followed by the implicit truncation inherent in integer casting). We already used 'rint()' for values that could be negative (where +0.5 is actively wrong), let's just make it consistent. Of course, as is usual for the messy C math functions, it depends on the current rounding mode. But the default round-to-nearest is what we want and use, and the functions that explicitly always round to nearest aren't standard enough to worry about. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- uemis.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'uemis.c') diff --git a/uemis.c b/uemis.c index 27e526f1d..c43606d9c 100644 --- a/uemis.c +++ b/uemis.c @@ -329,9 +329,9 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { * we store the incorrect working pressure to get the SAC calculations "close" * but the user will have to correct this manually */ - dive->cylinder[i].type.size.mliter = volume; + dive->cylinder[i].type.size.mliter = rint(volume); dive->cylinder[i].type.workingpressure.mbar = 202600; - dive->cylinder[i].gasmix.o2.permille = *(uint8_t *)(data+120+25*(gasoffset + i)) * 10 + 0.5; + dive->cylinder[i].gasmix.o2.permille = *(uint8_t *)(data+120+25*(gasoffset + i)) * 10; dive->cylinder[i].gasmix.he.permille = 0; } /* first byte of divelog data is at offset 0x123 */ -- cgit v1.2.3-70-g09d2