Post Go back to editing

Bug in sprintf_fixed32(char *out, fixed32_t in)?

Category: Software
Product Number: AduCM350BBZ (Software example code for the AduCM350 evaluation board)
Software Version: (December 2015)

There are a number of IAR examples that were delivered for use with the AduCM350 evaluation platform and many of them (CurrentProfiling_States.c, ImpedanceMeasurement_2Wire.c and ImpedanceMeasurement_4WireBioIsolated.c contain a function called "sprintf_fixed32".

I am not sure if this is the right forum but I believe that there is a bug in the supplied sprint_fixed32() function. When the number is negative, the last four fractional bits are inverted, as the in.full must be represented as a two's complement. However, the second part of the 2's increment (adding 1) is not performed on the fractional part as expected, but on the integral part instead (see screenshot with extra added comments.

I believe that the increment should be applied to the fractional part and not the integral part, as otherwise the example number of -3.14 would be printed out as -2.13 instead.

Please let me know if that is a genuine bug or if I have misunderstood the code.