Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: double to string causes divide by zero!



On Feb 27, 2004, at 11:49 AM, Rob Ross wrote:


And, because the vm handles the overloading of the +
operator, I don't think that there is any way for me to syncronize to
avoid this!

You can use a synchronized block:

synchronized (this) {
double d = some special double
String s = "";
s+=d;
}

Rob



I don't think this would work as each TestThread in my example is a separate object, ie:
for (int i = 0; i < numThreads; i++) {
TestThread t = new TestDouble.TestThread(d);
t.start();
}

The problem is that you really need to synchronize the FloatingDecimal.dtoa method, but that is hidden behind the vm's string operator overloading. And it could easily happen that some other thread, with a completely independent double and string, could cause the same problem. It is simply not possible to find all double to string conversions and syncronize them, especially when they may exist in external library code that you have no control over.

Oh well,
Philip
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >RE: double to string causes divide by zero! (From: "Rob Ross" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.