<html>
<head>
<style>
body {
  font-family: Verdana, sans-serif;
  font-size: 0.8em;
  color:#484848;
}
h1, h2, h3 { font-family: "Trebuchet MS", Verdana, sans-serif; margin: 0px; }
h1 { font-size: 1.2em; }
h2, h3 { font-size: 1.1em; }
a, a:link, a:visited { color: #2A5685;}
a:hover, a:active { color: #c61a1a; }
a.wiki-anchor { display: none; }
hr {
  width: 100%;
  height: 1px;
  background: #ccc;
  border: 0;
}
.footer {
  font-size: 0.8em;
  font-style: italic;
}
</style>
</head>
<body>
<span class="header"></span>
Issue #6439 has been updated by Christopher Brooks.

<ul>
  <li><strong>Status</strong> changed from <i>New</i> to <i>Closed</i></li>
  <li><strong>Assignee</strong> changed from <i>Derik Barseghian</i> to <i>Christopher Brooks</i></li>
  <li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li>
</ul>

<p>It is almost never a good idea to compare doubles without using an epsilon factor.  Because of rounding, doubles are unlikely to precisely represent a value.</p>


        <p>One workaround in the expression language is to use</p>


        <p>close(value1, value2)</p>


        <p>which is defined as:</p>


        <p>Return true if the first argument<br />is close to the second (within<br />EPSILON, where EPSILON is<br />a static public variable of this<br />class)</p>


        <p>Tokens also have an isCloseTo() method:</p>


        <p>/** Test whether the value of this Token is close to the argument                                      
     *  Token.  The argument and this token are converted to                                               
     *  equivalent types, and then compared.  Generally, this is the                                       
     *  higher of the type of this token and the argument type.                                            
     *  Subclasses should implement the protected _isCloseTo() method                                      
     *  to perform the correct type-specific operation.                                                    
     *  @see #isEqualTo                                                                                    
     *  @param rightArgument The token to test closeness of this token with.                               
     *  @param epsilon The value that we use to determine whether two                                      
     *   tokens are close.                                                                                 
     *  @return A boolean token that contains the value true if the                                        
     *   units of this token and the argument token are the same, and their                                
     *   values are close.                                                                                 
     *  @exception IllegalActionException If the argument token is not                                     
     *   of a type that can be compared with this token, or the units                                      
     *   are not the same.                                                                                 <br />     */<br />    public final BooleanToken isCloseTo(Token rightArgument, double epsilon)</p>


        <p>See 13.4.1 Invoking Methods in <a class="external" href="http://ptolemy.eecs.berkeley.edu/books/Systems/chapters/Expressions.pdf">http://ptolemy.eecs.berkeley.edu/books/Systems/chapters/Expressions.pdf</a></p>
<hr />
<h1><a href="https://projects.ecoinformatics.org/ecoinfo/issues/6439#change-21517">Bug #6439: Double rounding fails in some cases while evaluating Expressions</a></h1>

<ul>
<li>Author: Owsiak Michal</li>
<li>Status: Closed</li>
<li>Priority: Urgent</li>
<li>Assignee: Christopher Brooks</li>
<li>Category: actors</li>
<li>Target version: 2.3.0</li>
  <li>Bugzilla-Id: </li>
</ul>

<p>It seems that addition of doubles can produce values slightly different than they should to be.</p>


        <p>Please take a look at attached workflow (simple_error.xml).</p>


        <p>Condition that should be satisfied to escape the loop is: 1.7 > 1.5 + 0.1</p>


        <p>However, loop is interrupted sooner, because of incorrect calculation of doubles. Value of "p" is set to: 1.6000000000000003</p>


        <p>This, of course, makes it impossible to use doubles as check points for the loops.</p>


        <p>However, it seems that casting to string and back works fine (take a look at second workflow - simple.xml)</p>


        <p>Cheers</p>


        <p>Michal</p>


<hr />
<span class="footer"><p>You have received this notification because you have either subscribed to it, or are involved in it.<br />To change your notification preferences, please click here: <a class="external" href="https://projects.ecoinformatics.org/ecoinfo/my/account">https://projects.ecoinformatics.org/ecoinfo/my/account</a></p></span>
</body>
</html>