The Artima Developer Community
Sponsored Link

Java Buzz Forum
It All Depends on What the Meaning of Equals Equals

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
News Manager

Posts: 47623
Nickname: newsman
Registered: Apr, 2003

News Manager is the force behind the news at Artima.com.
It All Depends on What the Meaning of Equals Equals Posted: Mar 3, 2010 11:07 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by News Manager.
Original Post: It All Depends on What the Meaning of Equals Equals
Feed Title: Java Today
Feed URL: http://weblogs.java.net/blog/editors/index.rdf
Feed Description: Java Today on java.net
Latest Java Buzz Posts
Latest Java Buzz Posts by News Manager
Latest Posts From Java Today

Advertisement

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:

These subtleties of floating-point comparison were also germane on the Project Coin mailing list last year; the definition of floating-point equality was discussed in relation to adding support for relational operations based on a type implementing the Comparable interface. That thread also broached the complexities involved in comparing BigDecimal values.

Joe concludes his post with:

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.

Quite true!


In Java Today, Kirill Grouchnikov presents Drinking From The Firehose – Design Inspiration February 2010:

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 ...

Geertjan Wielenga has discovered a Radio Propagation Simulator on the NetBeans Platform:

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...

TheServerSide.com reports IBM releases OSGi and JPA beta frameworks for WebSphere:

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...

In the Weblogs, Masoud Kalili talks about OpenMQ, the Open source Message Queuing, for beginners and professionals (OpenMQ from A to Z):

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...

Juliano Viana talks about Java Enterprise Development - 2010 style:

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...

Jean-Francois Bonbhel asks Did you say JUG ? Java User ... What ?:

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 LWUIT forum, digitalsol has a question regarding Log class under Eclipse: Hello, I'm using Eclipse here for LWUIT development. I'm thinking of using this class https://lwuit.dev.java.net/nonav/javadocs/index.html for logging purposes. But in...

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...


Our current Spotlight is the LWUIT Featured App Gallery: Shai Almog's recent blog post, "Latest & Greatest In The LWUIT Featured Apps Gallery", highlights 13 new applications from the LWUIT Featured App Gallery. Multiple views of each application are presented. Currently 80 different LWUIT apps are featured in the gallery.


Our current java.net Poll asks How far back should Java retain backwards-compatibility? Voting will be open until Friday.


Our latest java.net Feature Article is Has JDBC Kept up with Enterprise Requirements? by Jesse Davis; in the article, Jesse invites us to look beyond Type 4 architecture to address the latest requirements of the enterprise Java ecosystem. We're also featuring Adhir Mehta's Java Tech article, Web Service Simulatino Using Servlets; and Maven Repository Managers for the Enterprise, by John Smart.


Current and upcoming Java Events:

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.

-- Kevin Farnham
O'Reilly Media
Twitter: @kevin_farnham

 

Read: It All Depends on What the Meaning of Equals Equals

Topic: Ed Miliband becomes latest victim of `Twitterjacking' scam Previous Topic   Next Topic Topic: Ron Paul 2012

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use