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) && !(defined(__OpenBSD__) && defined(__mips64__))
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);
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)));
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)) {
108 return rb_big_mul(rb_int2big(lx), rb_int2big(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);
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.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t VALUE
Type that represents a Ruby object.