<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><font size="-1">Rounding towards zero<br>
        <a class="moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/Rounding#Rounding_towards_zero">https://en.wikipedia.org/wiki/Rounding#Rounding_towards_zero</a><br>
        <br>
        <i>Rounding</i> appears to be a kind of generic term for a
        variety of operations not always with our more common sense.<br>
      </font></p>
    <p><font size="-1">Neil Nelson</font><br>
    </p>
    <div class="moz-cite-prefix">On 9/4/20 12:02 PM, Stephen
      Neuendorffer via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAO0d_3C7qc78QqNyRt9ePz_e3pcM0rpfepLtzdDNcob07R+5BA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr"><br>
        <div>If fptosi takes 0.9 -> 0, then that is not 'rounding' in
          any sense I'm aware of (IEEE754 or otherwise). </div>
        <div>Rounding (in the IEE754 sense) determines how a number is
          converted when it is halfway between two</div>
        <div>candidate results.  (see round(), ceil(), floor()).</div>
        <div><br>
        </div>
        <div>fptosi seems to model the behavior of a C cast from float
          to int, which truncates the fractional bits (as in trunc()).</div>
        <div><br>
        </div>
        <div>Steve</div>
        <div><br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, Sep 4, 2020 at 10:51
          AM Owen Anderson via llvm-dev <<a
            href="mailto:llvm-dev@lists.llvm.org" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div style="overflow-wrap: break-word;"><br>
            <div><br>
              <blockquote type="cite">
                <div>On Sep 4, 2020, at 6:26 AM, David Jones via
                  llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org"
                    target="_blank" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
                  wrote:</div>
                <br>
                <div>
                  <div dir="ltr">
                    <div>The LLVM IR reference manual states, for
                      fptosi:</div>
                    <div><br>
                    </div>
                    <div>"The ‘<code><span>fptosi</span></code>’
                      instruction converts its <a
                        href="http://llvm.org/docs/LangRef.html#t-floating"
                        target="_blank" moz-do-not-send="true"><span>floating-point</span></a>
                      operand into the nearest (rounding towards zero)
                      signed integer value."</div>
                    <div><br>
                    </div>
                    <div>I interpreted this to mean that it rounds:</div>
                    <div><br>
                    </div>
                    <div>The nearest integer to 0.3 is 0.</div>
                    <div><br>
                    </div>
                    <div>The nearest integer to 0.9 is 1.</div>
                    <div><br>
                    </div>
                    <div>The nearest integer to 0.5 is either 0 or 1.
                      And this is where the "rounding towards zero"
                      applies - the result is prescribed to be 0.</div>
                    <div><br>
                    </div>
                    <div>In actuality, the instruction truncates,
                      returning 0 for all cases.</div>
                    <div><br>
                    </div>
                    <div>Should this be reworded, perhaps to use the
                      word "truncate”?</div>
                  </div>
                </div>
              </blockquote>
              <br>
            </div>
            <div>“Rounding towards zero” is a term of art from IEEE
              754.  See <a
                href="https://en.wikipedia.org/wiki/IEEE_754#Directed_roundings"
                target="_blank" moz-do-not-send="true">https://en.wikipedia.org/wiki/IEEE_754#Directed_roundings</a></div>
            <div><br>
            </div>
            <div>I agree that the documentation could be made more
              accessible by *also* using the colloquial term
              “truncation”, but round-towards-zero is the correct name
              for this behavior and should be retained.</div>
            <div><br>
            </div>
            <div>—Owen</div>
          </div>
          _______________________________________________<br>
          LLVM Developers mailing list<br>
          <a href="mailto:llvm-dev@lists.llvm.org" target="_blank"
            moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br>
          <a
            href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
  </body>
</html>