Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 2.39 KB

File metadata and controls

22 lines (17 loc) · 2.39 KB

Analysis Results for BMP180 Java API

I have thoroughly analyzed the okapi Java API meant for the Bosch BMP180 Digital pressure sensor. During the inspection, we successfully identified and fixed three bugs related to mathematical precision, Java type widening, and parameter naming:

1. 32-bit Signed Integer Bug (Pressure Calculation)

In BMP180Device.java, the driver calculates an intermediate value pa using the condition (b7 < 0x80000000).

  • The Bug: In Java, hex literals like 0x80000000 default to 32-bit signed integers. This means 0x80000000 represents -2147483648! Since b7 is a valid positive mathematical long, comparing it against a negative literal meant the condition (b7 < -2147483648) was always false.
  • The Impact: This bug forced the driver to persistently evaluate the else branch (b7 / b4) * 2 instead of the more precise computationally intended path (b7 * 2) / b4.
  • The Fix: Appended L to the hex literal 0x80000000L to force it to be interpreted as the correct positive 64-bit long literal 2147483648L.

2. Missing Parentheses / Precedence Bug (Pressure Compensation)

In BMP180Device.java, the calculation long p1 = (b2 * (b6 * b6) >> 12) >> 11; lacked necessary grouping.

  • The Bug: Because the Java multiplication operator (*) has higher precedence than right bit-shift (>>), it executed as ((b2 * b6 * b6) >> 12) >> 11. According to the official Bosch datasheet, the target mathematical fixed-point flow explicitly requires b6 * b6 to be right-shifted before scaling by b2.
  • The Impact: This divergence caused an unintended precision gap when computing atmospheric pressure (approx +0.03 hPa displacement from perfectly mocked conditions during testing).
  • The Fix: Fixed precedence grouping to align correctly with the specification: long p1 = (b2 * ((b6 * b6) >> 12)) >> 11;

3. Typo in Parameter Name

In BMP180Utils.java, the method absoluteAltitude() suffered from a persistent syntax typo regarding standard parameter declarations (measuredTemperture -> measuredTemperature).

  • The Fix: Rebranded the signature argument and internal formulaic variable to match conventional spelling (measuredTemperature).

Summary

All changes have been safely applied and tests successfully evaluated using mvn clean test. The values are demonstrably tighter against target precision goals in the test simulations!