зеркало из https://github.com/github/ruby.git
internal/numeric.h rework
Marked MJIT_FUNC_EXPORTED functions as such. Other changes are rather cosmetic.
This commit is contained in:
Родитель
099778a6da
Коммит
f0c02a0949
|
@ -9,30 +9,13 @@
|
|||
* modify this file, provided that the conditions mentioned in the
|
||||
* file COPYING are met. Consult the file for details.
|
||||
*/
|
||||
#include "internal/bignum.h" /* for BIGNUM_POSITIVE_P */
|
||||
#include "internal/bits.h" /* for RUBY_BIT_ROTL */
|
||||
#include "internal/fixnum.h" /* for FIXNUM_POSITIVE_P */
|
||||
#include "internal/vm.h" /* for rb_method_basic_definition_p */
|
||||
#include "ruby/intern.h" /* for rb_cmperr */
|
||||
#include "ruby/ruby.h" /* for USE_FLONUM */
|
||||
|
||||
struct RFloat {
|
||||
struct RBasic basic;
|
||||
double float_value;
|
||||
};
|
||||
|
||||
#define RFLOAT(obj) (R_CAST(RFloat)(obj))
|
||||
|
||||
/* numeric.c */
|
||||
|
||||
#define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
|
||||
|
||||
#define FLOAT_ZERO_P(x) (RFLOAT_VALUE(x) == 0.0)
|
||||
|
||||
#ifndef ROUND_DEFAULT
|
||||
# define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
|
||||
#endif
|
||||
enum ruby_num_rounding_mode {
|
||||
RUBY_NUM_ROUND_HALF_UP,
|
||||
RUBY_NUM_ROUND_HALF_EVEN,
|
||||
RUBY_NUM_ROUND_HALF_DOWN,
|
||||
RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT
|
||||
};
|
||||
#define ROUND_TO(mode, even, up, down) \
|
||||
((mode) == RUBY_NUM_ROUND_HALF_EVEN ? even : \
|
||||
(mode) == RUBY_NUM_ROUND_HALF_UP ? up : down)
|
||||
|
@ -42,11 +25,29 @@ enum ruby_num_rounding_mode {
|
|||
ROUND_TO(mode, name##_half_even args, \
|
||||
name##_half_up args, name##_half_down args)
|
||||
|
||||
#ifndef ROUND_DEFAULT
|
||||
# define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
|
||||
#endif
|
||||
|
||||
enum ruby_num_rounding_mode {
|
||||
RUBY_NUM_ROUND_HALF_UP,
|
||||
RUBY_NUM_ROUND_HALF_EVEN,
|
||||
RUBY_NUM_ROUND_HALF_DOWN,
|
||||
RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT,
|
||||
};
|
||||
|
||||
struct RFloat {
|
||||
struct RBasic basic;
|
||||
double float_value;
|
||||
};
|
||||
|
||||
#define RFLOAT(obj) (R_CAST(RFloat)(obj))
|
||||
|
||||
/* numeric.c */
|
||||
int rb_num_to_uint(VALUE val, unsigned int *ret);
|
||||
VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
|
||||
double ruby_float_step_size(double beg, double end, double unit, int excl);
|
||||
int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endless);
|
||||
double ruby_float_mod(double x, double y);
|
||||
int rb_num_negative_p(VALUE);
|
||||
VALUE rb_int_succ(VALUE num);
|
||||
VALUE rb_int_uminus(VALUE num);
|
||||
|
@ -61,9 +62,7 @@ VALUE rb_int_idiv(VALUE x, VALUE y);
|
|||
VALUE rb_int_modulo(VALUE x, VALUE y);
|
||||
VALUE rb_int2str(VALUE num, int base);
|
||||
VALUE rb_fix_plus(VALUE x, VALUE y);
|
||||
VALUE rb_fix_aref(VALUE fix, VALUE idx);
|
||||
VALUE rb_int_gt(VALUE x, VALUE y);
|
||||
int rb_float_cmp(VALUE x, VALUE y);
|
||||
VALUE rb_float_gt(VALUE x, VALUE y);
|
||||
VALUE rb_int_ge(VALUE x, VALUE y);
|
||||
enum ruby_num_rounding_mode rb_num_get_rounding_option(VALUE opts);
|
||||
|
@ -82,12 +81,49 @@ int rb_int_positive_p(VALUE num);
|
|||
int rb_int_negative_p(VALUE num);
|
||||
VALUE rb_num_pow(VALUE x, VALUE y);
|
||||
VALUE rb_float_ceil(VALUE num, int ndigits);
|
||||
VALUE rb_float_abs(VALUE flt);
|
||||
static inline VALUE rb_num_compare_with_zero(VALUE num, ID mid);
|
||||
static inline int rb_num_positive_int_p(VALUE num);
|
||||
static inline int rb_num_negative_int_p(VALUE num);
|
||||
static inline double rb_float_flonum_value(VALUE v);
|
||||
static inline double rb_float_noflonum_value(VALUE v);
|
||||
static inline double rb_float_value_inline(VALUE v);
|
||||
static inline VALUE rb_float_new_inline(double d);
|
||||
static inline bool INT_NEGATIVE_P(VALUE num);
|
||||
static inline bool FLOAT_ZERO_P(VALUE num);
|
||||
#define rb_float_value rb_float_value_inline
|
||||
#define rb_float_new rb_float_new_inline
|
||||
|
||||
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);
|
||||
int rb_float_cmp(VALUE x, VALUE y);
|
||||
VALUE rb_float_eql(VALUE x, VALUE y);
|
||||
VALUE rb_fix_aref(VALUE fix, VALUE idx);
|
||||
MJIT_SYMBOL_EXPORT_END
|
||||
|
||||
static inline bool
|
||||
INT_NEGATIVE_P(VALUE num)
|
||||
{
|
||||
if (FIXNUM_P(num)) {
|
||||
return FIXNUM_NEGATIVE_P(num);
|
||||
}
|
||||
else {
|
||||
return BIGNUM_NEGATIVE_P(num);
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool
|
||||
FLOAT_ZERO_P(VALUE num)
|
||||
{
|
||||
return RFLOAT_VALUE(num) == 0.0;
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
rb_num_compare_with_zero(VALUE num, ID mid)
|
||||
|
@ -116,7 +152,6 @@ rb_num_positive_int_p(VALUE num)
|
|||
return RTEST(rb_num_compare_with_zero(num, mid));
|
||||
}
|
||||
|
||||
|
||||
static inline int
|
||||
rb_num_negative_int_p(VALUE num)
|
||||
{
|
||||
|
@ -133,12 +168,6 @@ rb_num_negative_int_p(VALUE num)
|
|||
return RTEST(rb_num_compare_with_zero(num, mid));
|
||||
}
|
||||
|
||||
|
||||
VALUE rb_float_abs(VALUE flt);
|
||||
VALUE rb_float_equal(VALUE x, VALUE y);
|
||||
VALUE rb_float_eql(VALUE x, VALUE y);
|
||||
VALUE rb_flo_div_flo(VALUE x, VALUE y);
|
||||
|
||||
static inline double
|
||||
rb_float_flonum_value(VALUE v)
|
||||
{
|
||||
|
@ -163,7 +192,7 @@ rb_float_flonum_value(VALUE v)
|
|||
static inline double
|
||||
rb_float_noflonum_value(VALUE v)
|
||||
{
|
||||
return ((struct RFloat *)v)->float_value;
|
||||
return RFLOAT(v)->float_value;
|
||||
}
|
||||
|
||||
static inline double
|
||||
|
@ -205,6 +234,4 @@ rb_float_new_inline(double d)
|
|||
return rb_float_new_in_heap(d);
|
||||
}
|
||||
|
||||
#define rb_float_value(v) rb_float_value_inline(v)
|
||||
#define rb_float_new(d) rb_float_new_inline(d)
|
||||
#endif /* INTERNAL_NUMERIC_H */
|
||||
|
|
Загрузка…
Ссылка в новой задаче