Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352817 - Operator precedence
Summary: Operator precedence
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-22 02:14 EDT by Jonathan Camilleri CLA
Modified: 2011-08-30 14:42 EDT (History)
2 users (show)

See Also:


Attachments
source (4.22 KB, application/octet-stream)
2011-07-22 02:14 EDT, Jonathan Camilleri CLA
no flags Details
screenshot (60.80 KB, image/gif)
2011-07-22 02:19 EDT, Jonathan Camilleri CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.