Commit d56bcd8e authored by Explorer09's avatar Explorer09
Browse files

Change variable 'dot' to avoid division by reciprocal.

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.
parent 2cad745e
......@@ -451,9 +451,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 = MIN(GraphMeterMode_pixPerRow * GRAPH_HEIGHT, MAX(1, data->values[i] / dot));
int v2 = MIN(GraphMeterMode_pixPerRow * GRAPH_HEIGHT, MAX(1, data->values[i+1] / dot));
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
int v1 = MIN(pix, MAX(1, data->values[i] * pix));
int v2 = MIN(pix, MAX(1, data->values[i+1] * pix));
for (int line = 0; line < GRAPH_HEIGHT; line++) {
int line1 = MIN(GraphMeterMode_pixPerRow, MAX(0, v1 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line))));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment