<div dir="ltr"><div>Hi Arsen,</div><div><br></div>On 9 October 2013 12:53, Arsen Hakobyan <span dir="ltr"><<a href="mailto:artinetstudio@gmail.com" target="_blank">artinetstudio@gmail.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> if (((a - 8.1) >= FLT_EPSILON) || ((a - 8.1) <= -FLT_EPSILON)) { //I am<br>
using FLT_EPSILON to check whether (a != 2.0).<br></blockquote><div><br></div><div>This comment is wrong. You're trying to check if subtraction has any residual value (module) due to floating point inaccuracies that are higher than FLT_EPSILON.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">with -O3 optimization level clang generates already incorrect LLVM IR:<br>
; Function Attrs: nounwind uwtable<br>
define i32 @main() #0 {<br>
entry:<br>
store i32 1, i32* @err, align 4, !tbaa !0<br>
ret i32 0<br>
}<br></blockquote><div><br></div><div>This is correct, since FLT_EPSILON is denormalized to 0.0, thus "(a - 8.1) >= FLT_EPSILON" -> "0.0 >= 0.0", which is always true, and that branch will always be taken, thus, err will always be equal 1.</div>
<div><br></div><div>If you change your float to double, you'll see that it no longer denormalizes, and err=0;</div><div><br></div><div>cheers,<br></div><div>--renato</div></div></div></div>