diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-10-26 20:14:19 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-10-26 20:17:00 +0900 |
commit | afdca0e780760e008e26f4c9fc7262a0a4fe56bb (patch) | |
tree | 01f2c8186c65bd792f8a57355f2e63c013da8510 /internal | |
parent | e1ecda297e1b184d824fb4045169a20bba98a9ea (diff) |
Fix unaligned access to `double` in RFloat
Diffstat (limited to 'internal')
-rw-r--r-- | internal/numeric.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/numeric.h b/internal/numeric.h index 6bb7baf204..3d88845a16 100644 --- a/internal/numeric.h +++ b/internal/numeric.h @@ -206,10 +206,22 @@ rb_float_flonum_value(VALUE v) return 0.0; } +#if SIZEOF_VALUE >= SIZEOF_DOUBLE || defined(UNALIGNED_WORD_ACCESS) +# define UNALIGNED_DOUBLE_ACCESS 1 +#else +# define UNALIGNED_DOUBLE_ACCESS 0 +#endif + static inline double rb_float_noflonum_value(VALUE v) { +#if UNALIGNED_DOUBLE_ACCESS return RFLOAT(v)->float_value; +#else + double d; + memcpy(&d, &RFLOAT(v)->float_value, sizeof(double)); + return d; +#endif } static inline double |