sr_analog_to_float: Avoid comparison between signed and unsigned.

The check for p == q is basically checking whether p/q == 1. We should
be normalising the rational before it gets here though, so in this case
we should have p == q == 1 here.
This commit is contained in:
Martin Ling 2015-09-07 09:15:52 +01:00 committed by Uwe Hermann
parent 53e5d3d14d
commit b07a1b04e5
1 changed files with 4 additions and 2 deletions

View File

@ -173,7 +173,8 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog,
if (analog->encoding->unitsize == sizeof(float)
&& analog->encoding->is_bigendian == bigendian
&& (analog->encoding->scale.p == analog->encoding->scale.q)
&& analog->encoding->scale.p == 1
&& analog->encoding->scale.q == 1
&& analog->encoding->offset.p / (float)analog->encoding->offset.q == 0) {
/* The data is already in the right format. */
memcpy(outbuf, analog->data, count * sizeof(float));
@ -187,7 +188,8 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog2 *analog,
((uint8_t *)outbuf)[i + (analog->encoding->unitsize - b)] =
((uint8_t *)analog->data)[i * analog->encoding->unitsize + b];
}
if (analog->encoding->scale.p != analog->encoding->scale.q)
if (analog->encoding->scale.p != 1
|| analog->encoding->scale.q != 1)
outbuf[i] = (outbuf[i] * analog->encoding->scale.p) / analog->encoding->scale.q;
offset = ((float)analog->encoding->offset.p / (float)analog->encoding->offset.q);
outbuf[i] += offset;