diff options
Diffstat (limited to 'internal/numeric.h')
-rw-r--r-- | internal/numeric.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/internal/numeric.h b/internal/numeric.h index 6bb7baf204..6406cfc2fa 100644 --- a/internal/numeric.h +++ b/internal/numeric.h @@ -35,9 +35,22 @@ enum ruby_num_rounding_mode { RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT, }; +/* same as internal.h */ +#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) +#define roomof(x, y) (((x) + (y) - 1) / (y)) +#define type_roomof(x, y) roomof(sizeof(x), sizeof(y)) + +#if SIZEOF_DOUBLE <= SIZEOF_VALUE +typedef double rb_float_value_type; +#else +typedef struct { + VALUE values[roomof(SIZEOF_DOUBLE, SIZEOF_VALUE)]; +} rb_float_value_type; +#endif + struct RFloat { struct RBasic basic; - double float_value; + rb_float_value_type float_value; }; #define RFLOAT(obj) ((struct RFloat *)(obj)) @@ -73,6 +86,7 @@ VALUE rb_int_equal(VALUE x, VALUE y); VALUE rb_int_divmod(VALUE x, VALUE y); VALUE rb_int_and(VALUE x, VALUE y); VALUE rb_int_lshift(VALUE x, VALUE y); +VALUE rb_int_rshift(VALUE x, VALUE y); VALUE rb_int_div(VALUE x, VALUE y); int rb_int_positive_p(VALUE num); int rb_int_negative_p(VALUE num); @@ -98,7 +112,6 @@ RUBY_SYMBOL_EXPORT_BEGIN /* numeric.c (export) */ RUBY_SYMBOL_EXPORT_END -MJIT_SYMBOL_EXPORT_BEGIN VALUE rb_flo_div_flo(VALUE x, VALUE y); double ruby_float_mod(double x, double y); VALUE rb_float_equal(VALUE x, VALUE y); @@ -112,7 +125,6 @@ VALUE rb_int_abs(VALUE num); VALUE rb_int_bit_length(VALUE num); VALUE rb_int_uminus(VALUE num); VALUE rb_int_comp(VALUE num); -MJIT_SYMBOL_EXPORT_END static inline bool INT_POSITIVE_P(VALUE num) @@ -147,7 +159,7 @@ rb_num_compare_with_zero(VALUE num, ID mid) { VALUE zero = INT2FIX(0); VALUE r = rb_check_funcall(num, mid, 1, &zero); - if (r == Qundef) { + if (RB_UNDEF_P(r)) { rb_cmperr(num, zero); } return r; @@ -209,7 +221,15 @@ rb_float_flonum_value(VALUE v) static inline double rb_float_noflonum_value(VALUE v) { +#if SIZEOF_DOUBLE <= SIZEOF_VALUE return RFLOAT(v)->float_value; +#else + union { + rb_float_value_type v; + double d; + } u = {RFLOAT(v)->float_value}; + return u.d; +#endif } static inline double |