summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2016-01-21 14:06:11 +0800
committerExplorer09 <explorer09@gmail.com>2016-01-21 14:06:11 +0800
commit040613db3315aeb992208d30789807285316f3b9 (patch)
tree27e71f686be35e22c7770fef41af0de57c05773c /Meter.c
parentd54ab24d9728e09965e7ed04fa3502a8420ba748 (diff)
Change variable 'dot' to avoid division by reciprocal.
(Cherry-picked from d56bcd8e0d8d6a177fc2e40db32fc73ea4588684, the experimental graph coloring branch) The variable 'dot' in GraphMeterMode_draw now means "maximum number of dots per value (column) in graph". The old meaning was "amount of value that is to be represented by a dot" and was always a fraction. Due to a limitation in floating point computing, if GRAPH_HEIGHT were not a power of 2, then rounding errors will occur on numbers like (1.0/3). (Currently GRAPH_HEIGHT is 4 and so no precision loss.) 'dot' was used as a divisor, and it's "division by a reciprocal". We change that to simple multiplication.
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Meter.c b/Meter.c
index 444d8f60..781d45c7 100644
--- a/Meter.c
+++ b/Meter.c
@@ -408,9 +408,9 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
}
for (int i = nValues - (w*2) + 2, k = 0; i < nValues; i+=2, k++) {
- const double dot = (1.0 / (GraphMeterMode_pixPerRow * GRAPH_HEIGHT));
- int v1 = CLAMP(data->values[i] / dot, 1, GraphMeterMode_pixPerRow * GRAPH_HEIGHT);
- int v2 = CLAMP(data->values[i+1] / dot, 1, GraphMeterMode_pixPerRow * GRAPH_HEIGHT);
+ int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
+ int v1 = CLAMP(data->values[i] * pix, 1, pix);
+ int v2 = CLAMP(data->values[i+1] * pix, 1, pix);
int colorIdx = GRAPH_1;
for (int line = 0; line < GRAPH_HEIGHT; line++) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy