Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352817

Summary: Operator precedence
Product: [Eclipse Project] JDT Reporter: Jonathan Camilleri <camilleri.jon>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, Michael_Rennie
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
source
none
screenshot none

Description Jonathan Camilleri CLA 2011-07-22 02:14:23 EDT
Build Identifier: 

The attached source code (lines 61-62) are used to create a graphic drawing as illustrated within the attached source code.

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);
}
return image;
...

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. 

JLS reads as follows for the multiplication operator (15.17.1): 

Multiplication is a commutative operation if the operand expressions have no side effects. While integer multiplication is associative when the operands are all of the same type.

References
1. Core Java Volume 1 (8th Edition), Table 3.4 ISBN-13: 978-0-13-235476-9
2. Core Java Volume 2 (7th Edition), ISBN 0-13-111826-9.
3. Java Language Specification (3rd Edition) 


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.

Reproducible: Always
Comment 1 Jonathan Camilleri CLA 2011-07-22 02:14:51 EDT
Created attachment 200143 [details]
source
Comment 2 Jonathan Camilleri CLA 2011-07-22 02:19:55 EDT
Created attachment 200144 [details]
screenshot
Comment 3 Michael Rennie CLA 2011-08-30 14:42:59 EDT
(In reply to comment #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. 

In the case mentioned the values for a and b are correct (-2) and Eclipse is showing these correct values.

> Information about Mandrelbot, and, the rationale behind these formulae would be
> appreciated.

Google would be a good place to start for information about Mandelbrot.