• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New "approximator" operator in Java

 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun announced today that they are adding several new operators to the Java language.

For example, the "approximator" operator is designed for specifying an estimated range. The syntax has two forms:
  • a(+-)b, which reads "a plus or minus b"
  • a(+-)b%, which reads "a plus or minus b percent"
  • This evaluates to a new instance of javax.af.Range (another addition to the API), which has conveniently overridden toString. For example...
    The output (under Java 7.1 Beta) is...
    Range: (93, 107)
    Range: (88, 112)


    [ April 03, 2006: Message edited by: marc weber ]
     
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The Range class itself looks interesting, with it's boolean isInTolerance(int) method, and boolean nearEnough(int) method. This will be useful for those who are working with statistical analysis and for those who are fudging their thesis data.
     
    Ranch Hand
    Posts: 100
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Wow! Just imagine the myriad opportunities for mind-boggling misuse!
     
    marc weber
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The overloaded version of nearEnough(double) has interesting possibilities when used in conjunction with Range.EPSILON, where EPSILON is "a final semi-constant representing any real number greater than zero."

    This would be useful for Real Analysis (especially with the new Sequence Interpreter). For example, the following code demonstrates a calculus limit...

    [ April 01, 2006: Message edited by: marc weber ]
     
    author & internet detective
    Posts: 41860
    908
    Eclipse IDE VI Editor Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by marc weber:
    The overloaded version of nearEnough(double) has interesting possibilities when used in conjunction with Range.EPSILON, where EPSILON is "a final semi-constant representing any real number greater than zero."


    Well as long as there is a double version That way the creative accountants can find a myraid of uses!
     
    marc weber
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This is an interesting change...

    Due to recent confusion regarding postfix operators, an explicit operator cast will be required in Java 7 to force traditional postfix behavior. In the absence of such a cast, the postfix operator will default to prefix operator behavior.


    For example...

    Obviously, this will break a lot of existing code, but the benefits are obvious.

    Ref: http://java.sun.com/april_release404.jsp
     
    Marshal
    Posts: 28175
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Oh good. Now we can be asked questions about the meaning of "a+-=a+-a".
     
    marc weber
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Paul Clapham:
    Oh good. Now we can be asked questions about the meaning of "a+-=a+-a".


    Or the Rough Estimate Pattern:

    a(+-)((+-)b%)
    a(+-)((+-)((+-)b%))
    a(+-)((+-)((+-)((+-)b%)))
    a(+-)((+-)((+-)((+-)((+-)b%))))
    a(+-)((+-)((+-)((+-)((+-)((+-)b%)))))
    etc.
    [ April 01, 2006: Message edited by: marc weber ]
     
    marc weber
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Whoops, I posted an invalid URL for the reference. The correct page is http://java.sun.com/april_release.jsp.
     
    (instanceof Sidekick)
    Posts: 8791
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Bout time Java catches up. In ANSI Standard REXX:

    1.3 Numeric fuzz

    The numeric fuzz setting identifies the number of digits of accuracy that are IGNORED during numeric comparisons. The fuzziness is set to the value of the fuzzExpression. When the fuzzExpression is absent, the fuzziness is set to the default setting -- 0 digits. The value of the fuzzExpression must be 0, or a positive whole number which is less than the current numeric digits setting.

    The fuzz built-in function returns the current setting of the numeric fuzz value.

    Note: the fuzz setting is rarely altered. It is useful for performing fuzzy logic computations. Normal computations should use a fuzz setting of 0.



    The numeric instruction.
     
    marc weber
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Moving to Meaningless Drivel.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic