Java High puzzles 87: tense relations

  In math, equal (=) definition of a true relationship between the equivalence between the number of (equivalence relation).    This equivalence relations will be divided into a set number of equivalence classes (equivalence class), each by the equivalent of the value of all the same composition of each other.    Other equivalence relations, including all triangles on the set of "equivalence" between the set and all of the "same page" of relations.    In fact, the relationship is a kind of equivalent to, if and only if it is reflexive, transmission and symmetrical.    These properties are defined as follows: 

  •   Reflexivity: for all x, x ~ x.    In other words, the value of each relationship to its own existence. 
  •   Transitivity: if x and y ~ y ~ z, x-z.    In other words, if the first value and the existence value of the second ~ relations, and the second and third values of relationship to exist, then the third with a value of ~ relations also exist. 
  •   Symmetry: If x ~ y, y ~ x.    In other words, if the first value and the second value relationship to exist, then the second value and the first value relationship to exist. 
  If you read the puzzles 29, will be able to know operator == is not reflexive, as expressions (Double.NaN == Double.NaN) was false, in the expression (Float.NaN == Float.NaN) is also so.    But operators == it is also in violation of the symmetry and transmission?    In fact, it is not in breach of symmetry: for all x and y values, (x = y) means (y = x).    Transitivity and it is entirely another matter.    35 puzzles for the operator == role in the original type of values inconsistent with the reasons for the transfer and provide clues.    When comparing the two types of the original values, operator == first upgrade to the binary data type (binary numeric promotion) [JLS 5.6.2].    This will result in these two values, there is a will widen the original type-(widening primitive conversion).    Most of the original type-broadening is not a problem, but there are three notable exceptions: int, or long float values into value, or value long into double duty, it will lead to loss of accuracy.    This loss of accuracy == operator can prove that the non-transfer of. 

  Implementation of the transfer of such tips is to use the three numerical comparison to the loss of two precision, and then with the facts can be the opposite result.    It can be constructed examples: Select two of the larger but not the same long-assign numerical x and z, and the first two will be a long numerical similar assign numerical double-y.    The following procedure is its code, it is the result of printing true true false, and this was clear proof of the operator == role in the original type of transmission is not. 


Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply