<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>My opinions about the solutions below ... <br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Am 13.02.2024 um 12:07 schrieb Thomas
      Kurz via fpc-pascal:<br>
    </div>
    <blockquote type="cite"
      cite="mid:791947261.20240213120736@smtp.mailbox.org">
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">But, sorry, because we are talking about compile time math, performance (nanoseconds) in this case doesn't count, IMO.



That's what i thought at first, too. But then I started thinking about how to deal with it and sumbled upon difficulties very soon:

a) 8427.0 + 33.0 / 1440.0
An easy case: all constants, so do the calculation at highest precision and reduce it afterwards, if possible.
</pre>
      </blockquote>
    </blockquote>
    I agree; I would say: <br>
    <span style="white-space: pre-wrap">all constants, so do the calculation at highest precision and reduce it afterwards, if required by the target </span>
    <blockquote type="cite"
      cite="mid:791947261.20240213120736@smtp.mailbox.org">
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">

b) var_single + 33.0 / 1440.0
Should also be feasable by evaluating the constant expression first, then reducing it to single (if possible) and adding the variable in the end.</pre>
      </blockquote>
    </blockquote>
    yes ... first evaluate the constant expression with maximum
    precision (best at compile time), then reduce the result. <br>
    The reduction to single must be done in any case, because the
    var_single in the expression dictates it, IMO<br>
    <blockquote type="cite"
      cite="mid:791947261.20240213120736@smtp.mailbox.org">
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">

c) 8427.0 + var_double / 1440.0
Because of using the double-type variable here, constants should be treated as double even at the cost of performance due to not knowing whether the result will be assigned to a single or double.</pre>
      </blockquote>
    </blockquote>
    yes<br>
    <blockquote type="cite"
      cite="mid:791947261.20240213120736@smtp.mailbox.org">
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">

d) 8427.0 + var_single / 1440.0
And this is the one I got to struggle with. And I can imagine this is the reason for the decision about how to handle decimal constants.
My first approach would have been to implicitly use single precision values throughout the expression. This would mean to lose precision if the result will be assigned to a double-precision variable. One could say: "bad luck - if the programmer intended to get better precision, he should have used a double-precision variable as in case c". But this wouldn't be any better than the current state we have now.</pre>
      </blockquote>
    </blockquote>
    8427.0 + (var_single / 1440.0)<br>
    <br>
    the 1440.0 can be reduced to single, because the other operand is
    single<br>
    and so the whole operation is done using single arithmetic. <br>
    <br>
    If here we had a FP constant instead of var_single, the whole
    operation IMO should be done <br>
    with maximum precision and at compile time in the best case. I have
    no problem that this <br>
    operation may give a different result with decimal constants than
    with explicitly typed <br>
    (reduced) FP variables. This can be easily explained to the users.
    Operations involving <br>
    FP variables with reduced precision may give reduced precision
    results. This seems to <br>
    be desirable for performance reasons and can be avoided by
    appropriate type casting. <br>
    <p><span style="white-space: pre-wrap">
</span></p>
    <p><span style="white-space: pre-wrap">
</span></p>
  </body>
</html>