1#ifndef INTERNAL_FIXNUM_H
2#define INTERNAL_FIXNUM_H
11#include "ruby/internal/config.h"
13#include "internal/bits.h"
14#include "internal/compilers.h"
19#if HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG
20# define DLONG LONG_LONG
21# define DL2NUM(x) LL2NUM(x)
22#elif defined(HAVE_INT128_T) && !(defined(__OpenBSD__) && defined(__mips64__))
23# define DLONG int128_t
24# define DL2NUM(x) (RB_FIXABLE(x) ? LONG2FIX(x) : rb_int128t2big(x))
25VALUE rb_int128t2big(int128_t n);
28static inline long rb_overflowed_fix_to_int(
long x);
35static inline bool FIXNUM_POSITIVE_P(
VALUE num);
36static inline bool FIXNUM_NEGATIVE_P(
VALUE num);
37static inline bool FIXNUM_ZERO_P(
VALUE num);
40rb_overflowed_fix_to_int(
long x)
42 return (
long)((
unsigned long)(x >> 1) ^ (1L
U << (SIZEOF_LONG * CHAR_BIT - 1)));
48#if !__has_builtin(__builtin_add_overflow)
73 if (__builtin_add_overflow((
long)x, (
long)y-1, &lz)) {
74 return rb_int2big(rb_overflowed_fix_to_int(lz));
85#if !__has_builtin(__builtin_sub_overflow)
90 if (__builtin_sub_overflow((
long)x, (
long)y-1, &lz)) {
91 return rb_int2big(rb_overflowed_fix_to_int(lz));
106 return DL2NUM((DLONG)lx * (DLONG)ly);
108 if (MUL_OVERFLOW_FIXNUM_P(lx, ly)) {
109 return rb_big_mul(rb_int2big(lx), rb_int2big(ly));
138 if (y > 0 ? mod < 0 : mod > 0) {
153 rb_fix_divmod_fix(x, y, &div, NULL);
164 rb_fix_divmod_fix(x, y, NULL, &mod);
169FIXNUM_POSITIVE_P(
VALUE num)
175FIXNUM_NEGATIVE_P(
VALUE num)
181FIXNUM_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.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t VALUE
Type that represents a Ruby object.