I found Joseph Darcy's recent post "Notions of Floating-Point Equality" interesting, informative, and even entertaining. If you've done scientific programming, you're probably familiar with the problems of floating point uncertainties, significant digits, divisions by zero that really wouldn't happen if you were doing the calculation with pencil and paper, tests of whether the values stored in two memory locations are equal, etc. It's a pain in the neck, really, dealing with these issues in a program.
So, what does the == operator really mean?
I'm kind of reminded of a famous quote from a former United States president. When asked a particular question, his response was: "It depends on what the meaning of the word 'is' is."
So what is the meaning of is? Or of ==?
Joe gets right to the point, in saying:
the "==" operator defined by IEEE 754 and used by Java for comparing floating-point values (JLSv3 §15.21.1) is not an equivalence relation. Equivalence relations satisfy three properties, reflexivity (something is equivalent to itself), symmetry (if a is equivalent to b, b is equivalent to a), and transitivity (if a is equivalent to b and b is equivalent to c, then a is equivalent to c).
One of the simplest tests in scientific programming for detecting numeric anomalies is to check if a value is equal to itself. Why is this useful? Because NaN (Not a Number) is not equal to itself. If variable X is NaN, then a test in Java (and other languages that implement the IEEE 754 standard) that compares X to itself returns a false conditional result:
x = [complicated equation involving divisions by the difference
between large numbers that are close to one another and
trigonometric operations involving of angles that are very
close to one another, etc.]
if (x == x) {
// keep processing
} else {
System.out.println("Cancelling processing: looks like we have a NaN");
}
So, why is Joe Darcy writing about floating point equality? It's related to a BigDecimal discussion that took place on the Project Coin mailing list:
While subtle, the different notions of numerical equality each serve a useful purpose and knowing which notion is appropriate for a given task is an important factor in writing correct programs.
Every month this series is tracking the latest design trends and collecting the best examples of modern web designs. Here is the list for February 2010 with almost 1400 links from 44 aggregator posts: * 40 Beautiful Corporate Websites from Vandelay Website Design ...
RaPSor is a simulator of radio propagation channels, based on more than 10 years of research. It is used both in research and for educational purpose at the University of Poitiers in France. Go to the RaPSor site on SourceForge and you will learn that one of RaPSor's main advantages is "its extensibility, allowing anyone to add new geometric primitives, new simulation algorithms, new usage of simulation results, or new kinds of antennas". Here are some screenshots I took after installing this cool application...
IBM announced the open beta of WebSphere Application Server feature packs for OSGi and JPA. The feature packs are product extensions that provide lightweight application frameworks for WebSphere V7. The company said they will allow organizations to realize many of the benefits found in open-source frameworks in a standardized, WebSphere-integrated fashion...
Talking about messaging imply two basic functionalities which all other provided features are built around them; these two capabilities include support for topics and queues which basically lets a message to be consumed by as many interested consumer as subscribed or at just one of the interested consumer(s). Messaging middleware was present in the industry before Java come along and every one of them had its own interfaces for providing the messaging services. There were no standard interfaces which vendors try to comply with it in order to increase the compatibility, interoperability, ease of use, and portability. The art of Java community was defining Java Messaging System (JMS) as a standard set of interfaces to interact with this type of middleware from Java based applications...
I woke up the other day and realized its 2010. When I was a kid, year 2000 was far, far away (well not quite, but hey when you are 7 years old 13 years is a long time). In 2001 we were supposed to be colonyzing the moon. In 2010, Jupiter would be within our reach. And there are reliable reports indicating that 9 years from now flying cars and aritificial life forms should be common place. I must admit: the kid within me feels kind of disappointed. On the other hand...
Is it still possible to ask this question in 2010? Isn’t the answer obvious ?Well no ! It was the question I was asking myself three years ago, even though I had been working as a consultant and Java trainer for seven years. In 2007, my ex-colleague Éric Marcoux (Oracle ACE Director) suggested I join JUG Québec (Canada). I said JUG ? Java User…What ?...
In the Forums, Oliver Gottwald has glassfish: JWSDP questions: I'm having issues getting JWSDP up and running. Iwas able to get a install for jwsdp-2_0-unix.sh installed but had to doa couple jumps threw flaming hoops from the following link...
In the Wonderland forum, pradeep_d has a question regarding Group Permission for custom authentication module: Hi, I want to know how user's are associated with group, We have a plan of creating a module for authentication using DB which is used by other application. We want all the application user's to access wonderland. So i created the module but...
Registered users can submit event listings for the java.net Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.
Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of java.net it will be archived along with other past issues in the java.net Archive.