1 #ifndef INTERNAL_FIXNUM_H
2 #define INTERNAL_FIXNUM_H
11 #include "ruby/internal/config.h"
13 #include "internal/compilers.h"
18 #if HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG
19 # define DLONG LONG_LONG
20 # define DL2NUM(x) LL2NUM(x)
21 #elif defined(HAVE_INT128_T)
22 # define DLONG int128_t
23 # define DL2NUM(x) (RB_FIXABLE(x) ? LONG2FIX(x) : rb_int128t2big(x))
24 VALUE rb_int128t2big(int128_t n);
27 static inline long rb_overflowed_fix_to_int(
long x);
34 static inline bool FIXNUM_POSITIVE_P(
VALUE num);
35 static inline bool FIXNUM_NEGATIVE_P(
VALUE num);
36 static inline bool FIXNUM_ZERO_P(
VALUE num);
39 rb_overflowed_fix_to_int(
long x)
41 return (
long)((
unsigned long)(x >> 1) ^ (1L
U << (SIZEOF_LONG * CHAR_BIT - 1)));
47 #if !__has_builtin(__builtin_add_overflow)
72 if (__builtin_add_overflow((
long)x, (
long)y-1, &lz)) {
73 return rb_int2big(rb_overflowed_fix_to_int(lz));
84 #if !__has_builtin(__builtin_sub_overflow)
89 if (__builtin_sub_overflow((
long)x, (
long)y-1, &lz)) {
90 return rb_int2big(rb_overflowed_fix_to_int(lz));
105 return DL2NUM((DLONG)lx * (DLONG)ly);
107 if (MUL_OVERFLOW_FIXNUM_P(lx, ly)) {
137 if (y > 0 ? mod < 0 : mod > 0) {
152 rb_fix_divmod_fix(x, y, &div, NULL);
163 rb_fix_divmod_fix(x, y, NULL, &mod);
168 FIXNUM_POSITIVE_P(
VALUE num)
174 FIXNUM_NEGATIVE_P(
VALUE num)
180 FIXNUM_ZERO_P(
VALUE num)
#define INT2FIX
Old name of RB_INT2FIX.
#define LONG2FIX
Old name of RB_INT2FIX.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define FIXNUM_MIN
Old name of RUBY_FIXNUM_MIN.
#define FIX2LONG
Old name of RB_FIX2LONG.
VALUE rb_big_mul(VALUE x, VALUE y)
Performs multiplication of the passed two objects.
VALUE rb_int2big(intptr_t i)
Converts a C's intptr_t into an instance of rb_cInteger.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t VALUE
Type that represents a Ruby object.