[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 19 06:43:11 PDT 2022


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/Floating.h:54-62
+  explicit operator int8_t() const { return toAPSInt().getExtValue(); }
+  explicit operator uint8_t() const { return toAPSInt().getExtValue(); }
+  explicit operator int16_t() const { return toAPSInt().getExtValue(); }
+  explicit operator uint16_t() const { return toAPSInt().getExtValue(); }
+  explicit operator int32_t() const { return toAPSInt().getExtValue(); }
+  explicit operator uint32_t() const { return toAPSInt().getExtValue(); }
+  explicit operator int64_t() const { return toAPSInt().getExtValue(); }
----------------
sepavloff wrote:
> tbaeder wrote:
> > sepavloff wrote:
> > > Conversions to integers are bitcasts+truncation but the conversion to bool is different. What semantics have these operations?
> > They are basically used for casting. I didn't mean to make the bool implementation different, just seemed to make sense to me to do it this way.
> If they are used for casting, they need to preserve value, that is conversion float->int32 should transform 1.0->0x00000001. The method `toAPSInt` uses bitcast, so it converts 1.0->0x3f800000. `APFloat::convertToInteger` should be used to make value-preverving conversion but it requires knowledge of rounding mode.
That's good to know, thanks.  I've already used `TowardZero` in `Floating::toSemantics()`, but that was more a guess.

Is the rounding mode I'm supposed to use simply `LangOptions::getDefaultRoundingMode()`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134859/new/

https://reviews.llvm.org/D134859



More information about the cfe-commits mailing list