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

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 19 02:32:06 PDT 2022


sepavloff 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(); }
----------------
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.


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

https://reviews.llvm.org/D134859



More information about the cfe-commits mailing list