[riot-notifications] [RIOT-OS/RIOT] bmp180: Fixes conversion bug (#11154)

Kees Bakker notifications at github.com
Mon Mar 11 22:55:17 CET 2019


keestux commented on this pull request.



> @@ -147,8 +147,8 @@ uint32_t bmp180_read_pressure(const bmp180_t *dev)
     x1 = ((int32_t)dev->calibration.ac3 * b6) >> 13;
     x2 = ((int32_t)dev->calibration.b1 * (b6 * b6) >> 12) >> 16;
     x3 = ((x1 + x2) + 2) >> 2;
-    b4 = (int32_t)dev->calibration.ac4 * (uint32_t)(x3+32768) >> 15;
-    b7 = ((uint32_t)up - b3) * (uint32_t)(50000UL >> OVERSAMPLING);
+    b4 = (((int32_t)dev->calibration.ac4) * (uint32_t)(x3+32768)) >> 15;
+    b7 = ((uint32_t)(up - b3)) * (uint32_t)(50000UL >> OVERSAMPLING);

Good catch.
Some of the added parens are correct, but there are also a few too many.
The original case has `(int32_t)dev->calibration.ac4`, which is not correct. That should have been `uint32_t`.

I suggest to make it as follows:

    b4 = ((uint32_t)dev->calibration.ac4 * (uint32_t)(x3 + 32768)) >> 15;
    b7 = (uint32_t)(up - b3) * (uint32_t)(50000UL >> OVERSAMPLING);

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11154#pullrequestreview-213105764
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190311/2dd5966e/attachment.html>


More information about the notifications mailing list