summaryrefslogtreecommitdiff
path: root/internal/numeric.h
diff options
context:
space:
mode:
Diffstat (limited to 'internal/numeric.h')
-rw-r--r--internal/numeric.h30
1 files changed, 24 insertions, 6 deletions
diff --git a/internal/numeric.h b/internal/numeric.h
index 82ba4c1cfb..6406cfc2fa 100644
--- a/internal/numeric.h
+++ b/internal/numeric.h
@@ -1,7 +1,6 @@
#ifndef INTERNAL_NUMERIC_H /*-*-C-*-vi:se ft=c:*/
#define INTERNAL_NUMERIC_H
/**
- * @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
@@ -36,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))
@@ -74,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);
@@ -97,10 +110,8 @@ static inline bool FLOAT_ZERO_P(VALUE num);
RUBY_SYMBOL_EXPORT_BEGIN
/* numeric.c (export) */
-VALUE rb_int_positive_pow(long x, unsigned long y);
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);
@@ -114,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)
@@ -149,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;
@@ -211,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