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))
24VALUE rb_int128t2big(int128_t n);
27static inline long rb_overflowed_fix_to_int(
long x);
28static inline VALUE rb_fix_plus_fix(VALUE x, VALUE y);
29static inline VALUE rb_fix_minus_fix(VALUE x, VALUE y);
30static inline VALUE rb_fix_mul_fix(VALUE x, VALUE y);
31static inline void rb_fix_divmod_fix(VALUE x, VALUE y, VALUE *divp, VALUE *modp);
32static inline VALUE rb_fix_div_fix(VALUE x, VALUE y);
33static inline VALUE rb_fix_mod_fix(VALUE x, VALUE y);
34static inline bool FIXNUM_POSITIVE_P(VALUE num);
35static inline bool FIXNUM_NEGATIVE_P(VALUE num);
36static inline bool FIXNUM_ZERO_P(VALUE num);
39rb_overflowed_fix_to_int(
long x)
41 return (
long)((
unsigned long)(x >> 1) ^ (1L
U << (SIZEOF_LONG * CHAR_BIT - 1)));
45rb_fix_plus_fix(VALUE x, VALUE y)
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));
82rb_fix_minus_fix(VALUE x, VALUE y)
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));
100rb_fix_mul_fix(VALUE x, VALUE y)
105 return DL2NUM((DLONG)lx * (DLONG)ly);
107 if (MUL_OVERFLOW_FIXNUM_P(lx, ly)) {
121rb_fix_divmod_fix(VALUE a, VALUE b, VALUE *divp, VALUE *modp)
137 if (y > 0 ? mod < 0 : mod > 0) {
149rb_fix_div_fix(VALUE x, VALUE y)
152 rb_fix_divmod_fix(x, y, &div, NULL);
160rb_fix_mod_fix(VALUE x, VALUE y)
163 rb_fix_divmod_fix(x, y, NULL, &mod);
168FIXNUM_POSITIVE_P(VALUE num)
174FIXNUM_NEGATIVE_P(VALUE num)
180FIXNUM_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.