<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">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">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>