]> sigrok.org Git - libsigrok.git/commitdiff
sr_analog_to_float: Avoid comparison between signed and unsigned.
authorMartin Ling <redacted>
Mon, 7 Sep 2015 08:15:52 +0000 (09:15 +0100)
committerUwe Hermann <redacted>
Sun, 20 Sep 2015 22:32:26 +0000 (00:32 +0200)
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.

src/analog.c

index db5ac1cf8315476ae3f9c60fc8b1c768897728f3..dd23d4b48cf5f5f53fe95575159c871c6c34b3a9 100644 (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;