|operator precedence issue? [message #699547]
||Thu, 21 July 2011 18:34
| Jonathan Camilleri
Registered: July 2009
The attached source code (lines 61-62) are used to create a graphic drawing as illustrated within Core Java Volume 2 (7th Edition).|
However, when walking through the code, I noticed that putting a breakpoint at lines 61/62,and, reading the values does not completely agree with my manual calculation:
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
double a = XMIN + i * (XMAX - XMIN) / width;
double b = YMIN + j * (YMAX - YMIN) / height;
if (!escapesToInfinity(a, b))
raster.setDataElements(i, j, colorData);
XMIN = -2.0
XMAX = 2.0
YMIN = -2.0
YMAX = 2.0
for i = 0 and j = 0
a = -2 + 0 * (2 - (-2)) /400 = -0.02
b = -2 + 0 * (2 - (-2)) /400 = -1.99
When debugging the code Eclipse reads -2.0 for both a and b, as intermediate values. Where am I confused or misled?
Information about Mandrelbot, and, the rationale behind these formulae would be appreciated.
Complete source code which is sourced from Core Java Volume 2 (7th Edition) is attached to reproduce the issue.
Is this a bug or a misunderstanding?
[Updated on: Fri, 22 July 2011 05:55]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01496 seconds