aspose file tools
The moose likes Beginning Java and the fly likes double call by reference? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "double call by reference?" Watch "double call by reference?" New topic
Author

double call by reference?

Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
look at this code:

what is the expected output? not what i thought.


Don't be shy, be quiet!
Azriel Abramovich
Ranch Hand

Joined: Dec 10, 2003
Posts: 38
stupid stupid me.
the correct code is:

it returns that d4==d3.
Why?
If d3=1.2e15 or less it returns false.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9944
    
    6

doubles don't really store the exact value. when you get to large numbers, like 1.2e15, do you really care about the least significant digits???
1,200,000,000,000,000 vs.
1,200,000,000,000,001
if we were required to care, then the range of floats and doubles would be MUCH smaller.
the non-technical way to describe it (since i can't give the technical one) is that as the numbers get bigger, there are actually gaps between the numbers that ARE represented. Or, you can only have 15 or so significant digits. if you're looking at a number with say 16 digits, the one's place is basically ignored (or assumed to be 0).
if you have a number with 20 digits, the last 5 are assumed to be 0. even if you add 1 to it, it gets sort of rounded off.
does that make sense?


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: double call by reference?
 
Similar Threads
Double / Float Doubt.
double behaviour
trouble with precision adding floats together
Question on Pass By Reference
Double Boolean Operations