[PATCH] D48456: [Fixed Point Arithmetic] Casting between fixed point types and other arithmetic types

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 26 01:49:16 PDT 2018


ebevhan added inline comments.


================
Comment at: lib/AST/ExprConstant.cpp:9501
+      return false;
+    return Success(Result.getInt() >> Scale, E);
+  }
----------------
ebevhan wrote:
> The shift here will not produce the correct rounding behavior for fixed-point to integer conversion. E-C says `Conversions from a fixed-point to an integer type round toward zero.` However, simply shifting will always round towards -inf.
> 
> If the fixed-point number is negative, you need to add `lowBits(Scale)` before performing the shift.
> 
> This operation here is also not the same as the FixedPointToBool emission in CodeGen.
Oops, this has nothing at all to do with FixedPointToBool. Forget about that.


Repository:
  rC Clang

https://reviews.llvm.org/D48456





More information about the cfe-commits mailing list