<div dir="ltr"><div>One might argue that 0 is "the value closest and no greater in magnitude than the infinitely precise result" of rounding 0.9 to an integer. But this seems like nitpicking.</div><div>I agree that Owen's suggestion of adding wording similar to the Wikipedia entry is a reasonable way to disambiguate.</div><div><br></div><div>Conversely, we can simply use the wording from the C standard as that is what the operation implements:<br></div><div><br></div><div>When a finite value of real floating type is converted to an integer type other than _Bool,<br>the fractional part is discarded (i.e., the value is truncated toward zero). If the value of<br>the integral part cannot be represented by the integer type, the behavior is undefined.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 4, 2020 at 2:02 PM Stephen Neuendorffer via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">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 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" target="_blank">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><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">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"><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">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">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>