Ruby: numeric.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions | Variables
numeric.c File Reference
`#include "ruby/internal/config.h"`
`#include <assert.h>`
`#include <ctype.h>`
`#include <math.h>`
`#include <stdio.h>`
`#include "id.h"`
`#include "internal.h"`
`#include "internal/array.h"`
`#include "internal/compilers.h"`
`#include "internal/complex.h"`
`#include "internal/enumerator.h"`
`#include "internal/gc.h"`
`#include "internal/hash.h"`
`#include "internal/numeric.h"`
`#include "internal/object.h"`
`#include "internal/rational.h"`
`#include "internal/util.h"`
`#include "internal/variable.h"`
`#include "ruby/encoding.h"`
`#include "ruby/util.h"`
`#include "builtin.h"`
`#include "integer.rbinc"`

Go to the source code of this file.

## Macros
#define | FLT_RADIX 2
#define | DBL_MIN 2.2250738585072014e-308
#define | DBL_MAX 1.7976931348623157e+308
#define | DBL_MIN_EXP (-1021)
#define | DBL_MAX_EXP 1024
#define | DBL_MIN_10_EXP (-307)
#define | DBL_MAX_10_EXP 308
#define | DBL_DIG 15
#define | DBL_MANT_DIG 53
#define | DBL_EPSILON 2.2204460492503131e-16
#define | id_div idDiv
#define | id_divmod idDivmod
#define | id_to_i idTo_i
#define | id_eq idEq
#define | id_cmp idCmp
#define | NUMERR_TYPE 1
#define | NUMERR_NEGATIVE 2
#define | NUMERR_TOOLARGE 3
#define | method_basic_p(klass) rb_method_basic_definition_p(klass, mid)
#define | num_clone rb_immutable_obj_clone
#define | num_dup num_uplus
#define | flo_eq rb_float_equal
#define | flo_eql rb_float_eql
#define | FLOAT_OUT_OF_RANGE(val, type)
#define | LONG_MIN_MINUS_ONE ((double)LONG_MIN-1)
#define | LONG_MAX_PLUS_ONE (2*(double)(LONG_MAX/2+1))
#define | ULONG_MAX_PLUS_ONE (2*(double)(ULONG_MAX/2+1))
#define | LONG_MIN_MINUS_ONE_IS_LESS_THAN(n)
#define | int_succ rb_int_succ
#define | int_pred rb_int_pred
#define | SQRT_LONG_MAX HALF_LONG_MSB
#define | FIT_SQRT_LONG(n) (((n)<SQRT_LONG_MAX)&&((n)>=-SQRT_LONG_MAX))
#define | DEFINE_INT_SQRT(rettype, prefix, argtype)
#define | RB_ULONG_IN_DOUBLE_P(n) 1
#define | RB_ULONG_TO_DOUBLE(n) (double)(n)
#define | RB_ULONG unsigned long
#define | domain_error(msg) rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)

## Functions
double | round (double x)
void | rb_num_zerodiv (void)
enum ruby_num_rounding_mode | rb_num_get_rounding_option (VALUE opts)
int | rb_num_to_uint (VALUE val, unsigned int *ret)
int | rb_int_positive_p (VALUE num)
int | rb_int_negative_p (VALUE num)
int | rb_num_negative_p (VALUE num)
VALUE | rb_num_coerce_bin (VALUE x, VALUE y, ID func)
VALUE | rb_num_coerce_cmp (VALUE x, VALUE y, ID func)
VALUE | rb_num_coerce_relop (VALUE x, VALUE y, ID func)
VALUE | rb_int_zero_p (VALUE num)
VALUE | rb_float_new_in_heap (double d)
VALUE | rb_float_uminus (VALUE flt)
VALUE | rb_float_plus (VALUE x, VALUE y)
VALUE | rb_float_minus (VALUE x, VALUE y)
VALUE | rb_float_mul (VALUE x, VALUE y)
VALUE | rb_flo_div_flo (VALUE x, VALUE y)
VALUE | rb_float_div (VALUE x, VALUE y)
double | ruby_float_mod (double x, double y)
VALUE | rb_float_pow (VALUE x, VALUE y)
VALUE | rb_float_equal (VALUE x, VALUE y)
VALUE | rb_dbl_cmp (double a, double b)
int | rb_float_cmp (VALUE x, VALUE y)
VALUE | rb_float_gt (VALUE x, VALUE y)
VALUE | rb_float_eql (VALUE x, VALUE y)
VALUE | rb_float_abs (VALUE flt)
VALUE | rb_flo_is_infinite_p (VALUE num)
VALUE | rb_flo_is_finite_p (VALUE num)
VALUE | rb_float_floor (VALUE num, int ndigits)
VALUE | rb_float_ceil (VALUE num, int ndigits)
VALUE | rb_int_truncate (VALUE num, int ndigits)
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)
VALUE | ruby_num_interval_step_size (VALUE from, VALUE to, VALUE step, int excl)
long | rb_num2long (VALUE val)
unsigned long | rb_num2ulong (VALUE val)
void | rb_out_of_int (SIGNED_VALUE num)
long | rb_num2int (VALUE val)
long | rb_fix2int (VALUE val)
unsigned long | rb_num2uint (VALUE val)
unsigned long | rb_fix2uint (VALUE val)
short | rb_num2short (VALUE val)
short | rb_fix2short (VALUE val)
unsigned short | rb_num2ushort (VALUE val)
unsigned short | rb_fix2ushort (VALUE val)
VALUE | rb_num2fix (VALUE val)
VALUE | rb_int_odd_p (VALUE num)
VALUE | rb_int_even_p (VALUE num)
VALUE | rb_int_succ (VALUE num)
VALUE | rb_enc_uint_chr (unsigned int code, rb_encoding *enc)
VALUE | rb_int_uminus (VALUE num)
VALUE | rb_fix2str (VALUE x, int base)
VALUE | rb_int2str (VALUE x, int base)
VALUE | rb_fix_plus (VALUE x, VALUE y)
VALUE | rb_int_plus (VALUE x, VALUE y)
VALUE | rb_int_minus (VALUE x, VALUE y)
VALUE | rb_int_mul (VALUE x, VALUE y)
double | rb_int_fdiv_double (VALUE x, VALUE y)
VALUE | rb_int_fdiv (VALUE x, VALUE y)
VALUE | rb_int_div (VALUE x, VALUE y)
VALUE | rb_int_idiv (VALUE x, VALUE y)
VALUE | rb_int_modulo (VALUE x, VALUE y)
VALUE | rb_int_divmod (VALUE x, VALUE y)
VALUE | rb_int_positive_pow (long x, unsigned long y)
VALUE | rb_int_pow (VALUE x, VALUE y)
VALUE | rb_num_pow (VALUE x, VALUE y)
VALUE | rb_int_equal (VALUE x, VALUE y)
VALUE | rb_int_cmp (VALUE x, VALUE y)
VALUE | rb_int_gt (VALUE x, VALUE y)
VALUE | rb_int_ge (VALUE x, VALUE y)
VALUE | rb_int_comp (VALUE num)
VALUE | rb_num_coerce_bit (VALUE x, VALUE y, ID func)
VALUE | rb_int_and (VALUE x, VALUE y)
VALUE | rb_int_lshift (VALUE x, VALUE y)
VALUE | rb_fix_aref (VALUE fix, VALUE idx)
VALUE | rb_int_abs (VALUE num)
VALUE | rb_int_bit_length (VALUE num)
VALUE | rb_big_isqrt (VALUE)
void | Init_Numeric (void)
double | rb_float_value (VALUE v)
VALUE | rb_float_new (double d)

## Variables
const union bytesequence4_or_float | rb_infinity = {{0x00, 0x00, 0x80, 0x7f}}
const union bytesequence4_or_float | rb_nan = {{0x00, 0x00, 0xc0, 0x7f}}
VALUE | rb_cNumeric
VALUE | rb_cFloat
VALUE | rb_cInteger
VALUE | rb_eZeroDivError
VALUE | rb_eFloatDomainError

## Macro Definition Documentation

## ◆ DBL_DIG

#define DBL_DIG 15

Definition at line 67 of file numeric.c.

## ◆ DBL_EPSILON

#define DBL_EPSILON 2.2204460492503131e-16

Definition at line 73 of file numeric.c.

## ◆ DBL_MANT_DIG

#define DBL_MANT_DIG 53

Definition at line 70 of file numeric.c.

## ◆ DBL_MAX

#define DBL_MAX 1.7976931348623157e+308

Definition at line 52 of file numeric.c.

## ◆ DBL_MAX_10_EXP

#define DBL_MAX_10_EXP 308

Definition at line 64 of file numeric.c.

## ◆ DBL_MAX_EXP

#define DBL_MAX_EXP 1024

Definition at line 58 of file numeric.c.

## ◆ DBL_MIN

#define DBL_MIN 2.2250738585072014e-308

Definition at line 49 of file numeric.c.

## ◆ DBL_MIN_10_EXP

#define DBL_MIN_10_EXP (-307)

Definition at line 61 of file numeric.c.

## ◆ DBL_MIN_EXP

#define DBL_MIN_EXP (-1021)

Definition at line 55 of file numeric.c.

## ◆ DEFINE_INT_SQRT

#define DEFINE_INT_SQRT | ( |  | rettype,
|  |  | prefix,
|  |  | argtype
| ) |  |

Value:
rettype \
prefix##_isqrt(argtype n) \
{ \
if (!argtype##_IN_DOUBLE_P(n)) { \
unsigned int b = bit_length(n); \
argtype t; \
rettype x = (rettype)(n >> (b/2+1)); \
x |= ((rettype)1LU << (b-1)/2); \
while ((t = n/x) < (argtype)x) x = (rettype)((x + t) >> 1); \
return x; \
} \
return (rettype)sqrt(argtype##_TO_DOUBLE(n)); \
}
bit_length
#define bit_length(x)
Definition: bits.h:140
t
#define t
Definition: symbol.c:253
U
Definition: dtoa.c:302

Definition at line 5286 of file numeric.c.

## ◆ domain_error

#define domain_error | ( |  | msg | ) | rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg)

Definition at line 5324 of file numeric.c.

## ◆ FIT_SQRT_LONG

#define FIT_SQRT_LONG | ( |  | n | ) | (((n)<SQRT_LONG_MAX)&&((n)>=-SQRT_LONG_MAX))

Definition at line 3650 of file numeric.c.

## ◆ flo_eq

#define flo_eq rb_float_equal

Definition at line 1440 of file numeric.c.

## ◆ flo_eql

#define flo_eql rb_float_eql

Definition at line 1702 of file numeric.c.

## ◆ FLOAT_OUT_OF_RANGE

#define FLOAT_OUT_OF_RANGE | ( |  | val,
|  |  | type
| ) |  |

Value:
do { \
char buf[24]; \
rb_raise(rb_eRangeError, "float %s out of range of "type, \
out_of_range_float(&buf, (val))); \
} while (0)
rb_eRangeError
VALUE rb_eRangeError
Definition: error.c:1061
buf
voidpf void * buf
Definition: ioapi.h:138
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56

Definition at line 2879 of file numeric.c.

## ◆ FLT_RADIX

#define FLT_RADIX 2

Definition at line 46 of file numeric.c.

## ◆ id_cmp

#define id_cmp idCmp

Definition at line 187 of file numeric.c.

## ◆ id_div

#define id_div idDiv

Definition at line 183 of file numeric.c.

## ◆ id_divmod

#define id_divmod idDivmod

Definition at line 184 of file numeric.c.

## ◆ id_eq

#define id_eq idEq

Definition at line 186 of file numeric.c.

## ◆ id_to_i

#define id_to_i idTo_i

Definition at line 185 of file numeric.c.

## ◆ int_pred

#define int_pred rb_int_pred

Definition at line 3375 of file numeric.c.

## ◆ int_succ

#define int_succ rb_int_succ

Definition at line 3349 of file numeric.c.

## ◆ LONG_MAX_PLUS_ONE

#define LONG_MAX_PLUS_ONE (2*(double)(LONG_MAX/2+1))

Definition at line 2886 of file numeric.c.

## ◆ LONG_MIN_MINUS_ONE

#define LONG_MIN_MINUS_ONE ((double)LONG_MIN-1)

Definition at line 2885 of file numeric.c.

## ◆ LONG_MIN_MINUS_ONE_IS_LESS_THAN

#define LONG_MIN_MINUS_ONE_IS_LESS_THAN | ( |  | n | ) |

Value:
(LONG_MIN_MINUS_ONE == (double)LONG_MIN ? \
LONG_MIN <= (n): \
LONG_MIN_MINUS_ONE < (n))
LONG_MIN
#define LONG_MIN
Definition: limits.h:40
LONG_MIN_MINUS_ONE
#define LONG_MIN_MINUS_ONE
Definition: numeric.c:2885

Definition at line 2888 of file numeric.c.

## ◆ method_basic_p

#define method_basic_p | ( |  | klass | ) | rb_method_basic_definition_p(klass, mid)

Definition at line 280 of file numeric.c.

## ◆ num_clone

#define num_clone rb_immutable_obj_clone

Definition at line 522 of file numeric.c.

## ◆ num_dup

#define num_dup num_uplus

Definition at line 538 of file numeric.c.

## ◆ NUMERR_NEGATIVE

#define NUMERR_NEGATIVE 2

## ◆ NUMERR_TOOLARGE

#define NUMERR_TOOLARGE 3

## ◆ NUMERR_TYPE

#define NUMERR_TYPE 1

## ◆ RB_ULONG

#define RB_ULONG unsigned long

Definition at line 5307 of file numeric.c.

## ◆ RB_ULONG_IN_DOUBLE_P

#define RB_ULONG_IN_DOUBLE_P | ( |  | n | ) | 1

Definition at line 5304 of file numeric.c.

## ◆ RB_ULONG_TO_DOUBLE

#define RB_ULONG_TO_DOUBLE | ( |  | n | ) | (double)(n)

Definition at line 5306 of file numeric.c.

## ◆ SQRT_LONG_MAX

#define SQRT_LONG_MAX HALF_LONG_MSB

Definition at line 3648 of file numeric.c.

## ◆ ULONG_MAX_PLUS_ONE

#define ULONG_MAX_PLUS_ONE (2*(double)(ULONG_MAX/2+1))

Definition at line 2887 of file numeric.c.

## Function Documentation

## ◆ Init_Numeric()

void Init_Numeric | ( | void |  | ) |

Definition at line 5483 of file numeric.c.

References CLASS_OF, DBL2NUM, DBL_DIG, DBL_EPSILON, DBL_MANT_DIG, DBL_MAX, DBL_MAX_10_EXP, DBL_MAX_EXP, DBL_MIN, DBL_MIN_10_EXP, DBL_MIN_EXP, flo_eq, flo_eql, FLT_RADIX, HUGE_VAL, INT2FIX, int_pred, int_succ, nan(), num_clone, num_dup, rb_cFloat, rb_cInteger, rb_cNumeric, rb_cObject, rb_define_alias(), rb_define_class(), rb_define_const(), rb_define_method, rb_define_singleton_method, rb_deprecate_constant, rb_eFloatDomainError, rb_eRangeError, rb_eStandardError, rb_eZeroDivError, rb_flo_is_finite_p(), rb_flo_is_infinite_p(), rb_float_abs(), rb_float_div(), rb_float_gt(), rb_float_minus(), rb_float_mul(), rb_float_plus(), rb_float_pow(), rb_float_uminus(), rb_include_module(), rb_int_and(), rb_int_cmp(), rb_int_div(), rb_int_divmod(), rb_int_equal(), rb_int_fdiv(), rb_int_ge(), rb_int_gt(), rb_int_idiv(), rb_int_lshift(), rb_int_minus(), rb_int_modulo(), rb_int_mul(), rb_int_plus(), rb_int_pow(), rb_int_powm(), rb_mComparable, rb_undef_alloc_func(), and rb_undef_method().

## ◆ rb_big_isqrt()

VALUE rb_big_isqrt | ( | VALUE | n | ) |

Definition at line 6908 of file bignum.c.

References BARY_TRUNC, BDIGIT, BDIGITS, BIGDIVREM_EXTRA_WORDS, len, NULL, rb_bdigit_dbl_isqrt, rb_cInteger, rb_gc_force_recycle(), t, ULL2NUM, and ULONG2NUM.

## ◆ rb_dbl_cmp()

VALUE rb_dbl_cmp | ( | double | a,
|  | double | b
| ) |  |

Definition at line 1465 of file numeric.c.

References INT2FIX, isnan, and Qnil.

Referenced by rb_rational_cmp().

## ◆ rb_enc_uint_chr()

VALUE rb_enc_uint_chr | ( | unsigned int | code,
|  | rb_encoding * | enc
| ) |  |

Definition at line 3391 of file numeric.c.

References ONIGERR_INVALID_CODE_POINT_VALUE, ONIGERR_TOO_BIG_WIDE_CHAR_VALUE, rb_enc_codelen(), rb_enc_mbcput, rb_enc_name, rb_enc_precise_mbclen(), rb_enc_str_new(), rb_eRangeError, rb_raise(), RSTRING_PTR, and str.

Referenced by rb_io_ungetc().

## ◆ rb_fix2int()

long rb_fix2int | ( | VALUE | val | ) |

Definition at line 3048 of file numeric.c.

References FIX2INT.

## ◆ rb_fix2short()

short rb_fix2short | ( | VALUE | val | ) |

Definition at line 3107 of file numeric.c.

References FIX2LONG, FIXNUM_P, num, and rb_num2long().

## ◆ rb_fix2str()

VALUE rb_fix2str | ( | VALUE | x,
|  | int | base
| ) |  |

Definition at line 3495 of file numeric.c.

References CHAR_BIT, FIX2LONG, int(), long(), neg, rb_bug(), rb_eArgError, rb_raise(), rb_usascii_str_new, rb_usascii_str_new2, ruby_digitmap, and SIZEOF_VALUE.

Referenced by ole_typedesc2val(), and rb_int2str().

## ◆ rb_fix2uint()

unsigned long rb_fix2uint | ( | VALUE | val | ) |

Definition at line 3060 of file numeric.c.

References RB_FIX2ULONG.

## ◆ rb_fix2ushort()

unsigned short rb_fix2ushort | ( | VALUE | val | ) |

Definition at line 3126 of file numeric.c.

References FIX2ULONG, FIXNUM_P, num, and rb_num2ushort().

## ◆ rb_fix_aref()

VALUE rb_fix_aref | ( | VALUE | fix,
|  | VALUE | idx
| ) |  |

Definition at line 4613 of file numeric.c.

References CHAR_BIT, FIX2LONG, FIXNUM_P, INT2FIX, rb_big_norm(), and rb_to_int().

## ◆ rb_fix_plus()

VALUE rb_fix_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3591 of file numeric.c.

## ◆ rb_flo_div_flo()

VALUE rb_flo_div_flo | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1140 of file numeric.c.

References DBL2NUM, num, and RFLOAT_VALUE.

Referenced by rb_big_fdiv_double(), and rb_rational_div().

## ◆ rb_flo_is_finite_p()

VALUE rb_flo_is_finite_p | ( | VALUE | num | ) |

Definition at line 1804 of file numeric.c.

References isfinite, isinf(), isnan, num, Qfalse, Qtrue, and RFLOAT_VALUE.

Referenced by Init_Numeric().

## ◆ rb_flo_is_infinite_p()

VALUE rb_flo_is_infinite_p | ( | VALUE | num | ) |

Definition at line 1784 of file numeric.c.

References INT2FIX, isinf(), num, Qnil, and RFLOAT_VALUE.

Referenced by Init_Numeric().

## ◆ rb_float_abs()

VALUE rb_float_abs | ( | VALUE | flt | ) |

Definition at line 1732 of file numeric.c.

References DBL2NUM, and RFLOAT_VALUE.

Referenced by Init_Numeric().

## ◆ rb_float_ceil()

VALUE rb_float_ceil | ( | VALUE | num,
|  | int | ndigits
| ) |  |

Definition at line 2059 of file numeric.c.

References DBL2NUM, f, INT2FIX, num, and RFLOAT_VALUE.

## ◆ rb_float_cmp()

int rb_float_cmp | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1521 of file numeric.c.

References NUM2INT.

## ◆ rb_float_div()

VALUE rb_float_div | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1156 of file numeric.c.

References DBL2NUM, FIX2LONG, num, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by fun2(), and Init_Numeric().

## ◆ rb_float_eql()

VALUE rb_float_eql | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1688 of file numeric.c.

References isnan, Qfalse, Qtrue, RFLOAT_VALUE, and T_FLOAT.

## ◆ rb_float_equal()

VALUE rb_float_equal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1417 of file numeric.c.

References isnan, Qfalse, Qtrue, rb_integer_float_eq(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

## ◆ rb_float_floor()

VALUE rb_float_floor | ( | VALUE | num,
|  | int | ndigits
| ) |  |

Definition at line 1935 of file numeric.c.

References DBL2NUM, f, INT2FIX, num, and RFLOAT_VALUE.

## ◆ rb_float_gt()

VALUE rb_float_gt | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1537 of file numeric.c.

References FIX2LONG, FIXNUM_P, isnan, Qfalse, Qtrue, rb_integer_float_cmp(), rb_num_coerce_relop(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_minus()

VALUE rb_float_minus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1078 of file numeric.c.

References DBL2NUM, FIX2LONG, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_mul()

VALUE rb_float_mul | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1102 of file numeric.c.

References DBL2NUM, FIX2LONG, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_new()

VALUE rb_float_new | ( | double | d | ) |

Definition at line 5732 of file numeric.c.

## ◆ rb_float_new_in_heap()

VALUE rb_float_new_in_heap | ( | double | d | ) |

Definition at line 922 of file numeric.c.

References FL_WB_PROTECTED, NEWOBJ_OF, OBJ_FREEZE, rb_cFloat, RGENGC_WB_PROTECTED_FLOAT, and T_FLOAT.

## ◆ rb_float_plus()

VALUE rb_float_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1054 of file numeric.c.

References DBL2NUM, FIX2LONG, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_pow()

VALUE rb_float_pow | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1328 of file numeric.c.

References DBL2NUM, FIX2LONG, idPow, INT2FIX, rb_big2dbl(), rb_dbl_complex_new_polar_pi(), rb_num_coerce_bin(), RFLOAT_VALUE, round(), T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric(), rb_num_pow(), and rb_rational_pow().

## ◆ rb_float_uminus()

VALUE rb_float_uminus | ( | VALUE | flt | ) |

Definition at line 1041 of file numeric.c.

References DBL2NUM, and RFLOAT_VALUE.

Referenced by Init_Numeric().

## ◆ rb_float_value()

double rb_float_value | ( | VALUE | v | ) |

Definition at line 5725 of file numeric.c.

## ◆ rb_int2str()

VALUE rb_int2str | ( | VALUE | x,
|  | int | base
| ) |  |

Definition at line 3549 of file numeric.c.

References FIXNUM_P, rb_any_to_s(), rb_big2str(), rb_fix2str(), and T_BIGNUM.

Referenced by rb_str_format().

## ◆ rb_int_abs()

VALUE rb_int_abs | ( | VALUE | num | ) |

Definition at line 4826 of file numeric.c.

References FIXNUM_P, num, Qnil, rb_big_abs(), and T_BIGNUM.

Referenced by rb_rational_abs().

## ◆ rb_int_and()

VALUE rb_int_and | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4436 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_and(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_bit_length()

VALUE rb_int_bit_length | ( | VALUE | num | ) |

Definition at line 4881 of file numeric.c.

References FIXNUM_P, num, Qnil, rb_big_bit_length(), and T_BIGNUM.

## ◆ rb_int_cmp()

VALUE rb_int_cmp | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4196 of file numeric.c.

References FIXNUM_P, rb_big_cmp(), rb_eNotImpError, rb_obj_classname(), rb_raise(), and T_BIGNUM.

Referenced by Init_Numeric(), and rb_rational_cmp().

## ◆ rb_int_comp()

VALUE rb_int_comp | ( | VALUE | num | ) |

Definition at line 4372 of file numeric.c.

References FIXNUM_P, num, Qnil, rb_big_comp(), and T_BIGNUM.

## ◆ rb_int_div()

VALUE rb_int_div | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3803 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_div(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_divmod()

VALUE rb_int_divmod | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3950 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_divmod(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_equal()

VALUE rb_int_equal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4147 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_eq(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_even_p()

VALUE rb_int_even_p | ( | VALUE | num | ) |

Definition at line 3273 of file numeric.c.

References num.

## ◆ rb_int_fdiv()

VALUE rb_int_fdiv | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3748 of file numeric.c.

References DBL2NUM, Qnil, rb_int_fdiv_double(), and RB_INTEGER_TYPE_P.

Referenced by Init_Numeric().

## ◆ rb_int_fdiv_double()

double rb_int_fdiv_double | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3715 of file numeric.c.

References FIXNUM_P, gcd(), nan(), rb_big_fdiv_double(), rb_gcd(), rb_int_idiv(), RB_INTEGER_TYPE_P, and T_BIGNUM.

Referenced by rb_int_fdiv().

## ◆ rb_int_ge()

VALUE rb_int_ge | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4276 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_ge(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_gt()

VALUE rb_int_gt | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4236 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_gt(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_idiv()

VALUE rb_int_idiv | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3830 of file numeric.c.

References FIXNUM_P, rb_big_idiv(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_int_fdiv_double(), and rb_str_format().

## ◆ rb_int_lshift()

VALUE rb_int_lshift | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4553 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_lshift(), and T_BIGNUM.

Referenced by Init_Numeric(), and rb_flt_rationalize().

## ◆ rb_int_minus()

VALUE rb_int_minus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3636 of file numeric.c.

References FIXNUM_P, rb_big_minus(), rb_num_coerce_bin(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_flt_rationalize(), rb_int_truncate(), rb_rational_cmp(), and rb_rational_minus().

## ◆ rb_int_modulo()

VALUE rb_int_modulo | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3873 of file numeric.c.

References FIXNUM_P, rb_big_modulo(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_int_powm(), rb_int_truncate(), and rb_io_ungetbyte().

## ◆ rb_int_mul()

VALUE rb_int_mul | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3686 of file numeric.c.

References FIXNUM_P, rb_big_mul(), rb_num_coerce_bin(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_flt_rationalize(), rb_rational_cmp(), rb_rational_minus(), rb_rational_plus(), and rb_str_format().

## ◆ rb_int_negative_p()

int rb_int_negative_p | ( | VALUE | num | ) |

Definition at line 313 of file numeric.c.

References num.

Referenced by rb_int_powm().

## ◆ rb_int_odd_p()

VALUE rb_int_odd_p | ( | VALUE | num | ) |

Definition at line 3243 of file numeric.c.

References assert, FIXNUM_P, num, Qfalse, Qtrue, rb_big_odd_p(), and T_BIGNUM.

Referenced by rb_rational_pow().

## ◆ rb_int_plus()

VALUE rb_int_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3597 of file numeric.c.

References FIXNUM_P, rb_big_plus(), rb_num_coerce_bin(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_flt_rationalize(), rb_int_truncate(), rb_rational_plus(), and rb_str_format().

## ◆ rb_int_positive_p()

int rb_int_positive_p | ( | VALUE | num | ) |

Definition at line 307 of file numeric.c.

References num.

## ◆ rb_int_positive_pow()

VALUE rb_int_positive_pow | ( | long | x,
|  | unsigned long | y
| ) |  |

Definition at line 4022 of file numeric.c.

Referenced by date_zone_to_diff(), rb_flt_rationalize(), and rb_str_format().

## ◆ rb_int_pow()

VALUE rb_int_pow | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4088 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_pow(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_int_powm(), rb_num_pow(), and rb_rational_pow().

## ◆ rb_int_succ()

VALUE rb_int_succ | ( | VALUE | num | ) |

Definition at line 3337 of file numeric.c.

References FIX2LONG, FIXNUM_P, INT2FIX, LONG2NUM, num, rb_big_plus(), and T_BIGNUM.

## ◆ rb_int_truncate()

VALUE rb_int_truncate | ( | VALUE | num,
|  | int | ndigits
| ) |  |

Definition at line 2226 of file numeric.c.

References f, FIX2LONG, FIXNUM_P, INT2FIX, LONG2NUM, neg, num, rb_int_minus(), rb_int_modulo(), rb_int_plus(), SIGNED_VALUE, and T_FLOAT.

## ◆ rb_int_uminus()

VALUE rb_int_uminus | ( | VALUE | num | ) |

Definition at line 3466 of file numeric.c.

References assert, FIXNUM_P, num, rb_big_uminus(), and T_BIGNUM.

Referenced by rb_complex_pow(), rb_int_powm(), rb_rational_pow(), rb_rational_raw(), and rb_rational_uminus().

## ◆ rb_int_zero_p()

VALUE rb_int_zero_p | ( | VALUE | num | ) |

Definition at line 800 of file numeric.c.

References num.

## ◆ rb_num2fix()

VALUE rb_num2fix | ( | VALUE | val | ) |

Definition at line 3140 of file numeric.c.

References FIXABLE, FIXNUM_P, LONG2FIX, rb_eRangeError, rb_num2long(), and rb_raise().

## ◆ rb_num2int()

long rb_num2int | ( | VALUE | val | ) |

Definition at line 3042 of file numeric.c.

References rb_num2long().

## ◆ rb_num2long()

long rb_num2long | ( | VALUE | val | ) |

Definition at line 2894 of file numeric.c.

References FIX2LONG, FIXNUM_P, FLOAT_OUT_OF_RANGE, LONG_MAX_PLUS_ONE, LONG_MIN_MINUS_ONE_IS_LESS_THAN, NIL_P, rb_big2long(), rb_eTypeError, rb_raise(), rb_to_int(), RFLOAT_VALUE, T_BIGNUM, and T_FLOAT.

Referenced by rb_fix2short(), rb_num2fix(), rb_num2int(), and rb_num2short().

## ◆ rb_num2short()

short rb_num2short | ( | VALUE | val | ) |

Definition at line 3098 of file numeric.c.

References num, and rb_num2long().

## ◆ rb_num2uint()

unsigned long rb_num2uint | ( | VALUE | val | ) |

Definition at line 3054 of file numeric.c.

References rb_num2ulong().

## ◆ rb_num2ulong()

unsigned long rb_num2ulong | ( | VALUE | val | ) |

Definition at line 2963 of file numeric.c.

References NULL.

Referenced by rb_num2uint().

## ◆ rb_num2ushort()

unsigned short rb_num2ushort | ( | VALUE | val | ) |

Definition at line 3116 of file numeric.c.

References num.

Referenced by rb_fix2ushort().

## ◆ rb_num_coerce_bin()

VALUE rb_num_coerce_bin | ( | VALUE | x,
|  | VALUE | y,
|  | ID | func
| ) |  |

Definition at line 452 of file numeric.c.

References rb_funcall(), and TRUE.

Referenced by rb_big_divmod(), rb_big_fdiv_double(), rb_big_minus(), rb_big_modulo(), rb_big_mul(), rb_big_plus(), rb_big_pow(), rb_big_remainder(), rb_complex_minus(), rb_complex_mul(), rb_complex_plus(), rb_complex_pow(), rb_float_div(), rb_float_minus(), rb_float_mul(), rb_float_plus(), rb_float_pow(), rb_int_minus(), rb_int_mul(), rb_int_plus(), rb_rational_div(), rb_rational_minus(), rb_rational_mul(), rb_rational_plus(), and rb_rational_pow().

## ◆ rb_num_coerce_bit()

VALUE rb_num_coerce_bit | ( | VALUE | x,
|  | VALUE | y,
|  | ID | func
| ) |  |

Definition at line 4395 of file numeric.c.

References Qundef, rb_exec_recursive_paired(), and TRUE.

Referenced by rb_big_and(), rb_big_or(), and rb_big_xor().

## ◆ rb_num_coerce_cmp()

VALUE rb_num_coerce_cmp | ( | VALUE | x,
|  | VALUE | y,
|  | ID | func
| ) |  |

Definition at line 459 of file numeric.c.

References FALSE, Qnil, and rb_funcall().

Referenced by rb_big_cmp(), rb_rational_cmp(), and ruby_num_interval_step_size().

## ◆ rb_num_coerce_relop()

VALUE rb_num_coerce_relop | ( | VALUE | x,
|  | VALUE | y,
|  | ID | func
| ) |  |

Definition at line 474 of file numeric.c.

References FALSE, Qnil, rb_cmperr(), rb_funcall(), and UNREACHABLE_RETURN.

Referenced by rb_float_gt().

## ◆ rb_num_get_rounding_option()

enum ruby_num_rounding_mode rb_num_get_rounding_option | ( | VALUE | opts | ) |

Definition at line 205 of file numeric.c.

References NIL_P, PRIsVALUE, rb_check_string_type(), rb_eArgError, rb_get_kwargs(), rb_memcicmp(), rb_must_asciicompat(), rb_raise(), rb_sym2str(), RSTRING_LEN, RSTRING_PTR, RUBY_NUM_ROUND_DEFAULT, RUBY_NUM_ROUND_HALF_DOWN, RUBY_NUM_ROUND_HALF_EVEN, RUBY_NUM_ROUND_HALF_UP, str, strncasecmp, SYMBOL_P, and T_STRING.

## ◆ rb_num_negative_p()

int rb_num_negative_p | ( | VALUE | num | ) |

Definition at line 319 of file numeric.c.

References num.

Referenced by rb_random_ulong_limited(), and rb_rational_pow().

## ◆ rb_num_pow()

VALUE rb_num_pow | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4100 of file numeric.c.

References BUILTIN_TYPE, NIL_P, Qnil, rb_complex_pow(), rb_float_pow(), rb_int_pow(), rb_rational_pow(), SPECIAL_CONST_P, T_COMPLEX, and T_RATIONAL.

Referenced by rb_complex_pow().

## ◆ rb_num_to_uint()

int rb_num_to_uint | ( | VALUE | val,
|  | unsigned int * | ret
| ) |  |

Definition at line 250 of file numeric.c.

References FIX2LONG, FIXNUM_P, int(), NULL, NUMERR_NEGATIVE, NUMERR_TOOLARGE, NUMERR_TYPE, rb_absint_size(), rb_big2ulong(), and T_BIGNUM.

Referenced by rb_str_concat().

## ◆ rb_num_zerodiv()

void rb_num_zerodiv | ( | void |  | ) |

Definition at line 199 of file numeric.c.

References rb_eZeroDivError, and rb_raise().

Referenced by rb_big_divrem_normal(), rb_int_powm(), rb_rational_div(), and rb_rational_pow().

## ◆ rb_out_of_int()

void rb_out_of_int | ( | SIGNED_VALUE | num | ) |

Definition at line 2969 of file numeric.c.

References num, PRIdVALUE, rb_eRangeError, and rb_raise().

## ◆ round()

double round | ( | double | x | ) |

Definition at line 92 of file numeric.c.

References f.

Referenced by rb_float_pow().

## ◆ ruby_float_mod()

double ruby_float_mod | ( | double | x,
|  | double | y
| ) |  |

Definition at line 1237 of file numeric.c.

References mod.

## ◆ ruby_float_step()

int ruby_float_step | ( | VALUE | from,
|  | VALUE | to,
|  | VALUE | step,
|  | int | excl,
|  | int | allow_endless
| ) |  |

Definition at line 2566 of file numeric.c.

References DBL2NUM, FALSE, HUGE_VAL, isinf(), NIL_P, NUM2DBL, rb_yield(), ruby_float_step_size(), T_FLOAT, and TRUE.

## ◆ ruby_float_step_size()

double ruby_float_step_size | ( | double | beg,
|  | double | end,
|  | double | unit,
|  | int | excl
| ) |  |

Definition at line 2537 of file numeric.c.

References DBL_EPSILON, err, HUGE_VAL, and isinf().

Referenced by ruby_float_step(), and ruby_num_interval_step_size().

## ◆ ruby_num_interval_step_size()

VALUE ruby_num_interval_step_size | ( | VALUE | from,
|  | VALUE | to,
|  | VALUE | step,
|  | int | excl
| ) |  |

Definition at line 2597 of file numeric.c.

References DBL2NUM, FIX2LONG, FIXNUM_P, HUGE_VAL, id_cmp, id_div, INT2FIX, isinf(), LONG2FIX, NUM2DBL, POSFIXABLE, rb_cmpint, rb_dbl2big(), rb_funcall(), rb_num_coerce_cmp(), RTEST, ruby_float_step_size(), T_FLOAT, and ULONG2NUM.

## Variable Documentation

## ◆ rb_cFloat

VALUE rb_cFloat

Definition at line 190 of file numeric.c.

Referenced by Init_Complex(), Init_Numeric(), Init_Rational(), and rb_float_new_in_heap().

## ◆ rb_cInteger

VALUE rb_cInteger

Definition at line 191 of file numeric.c.

Referenced by Init_Bignum(), Init_Numeric(), Init_Rational(), rb_big_isqrt(), and rb_num_to_dbl().

## ◆ rb_cNumeric

VALUE rb_cNumeric

Definition at line 189 of file numeric.c.

Referenced by Init_bigdecimal(), Init_Complex(), Init_Numeric(), Init_Rational(), rb_check_to_float(), and rb_node_case_when_optimizable_literal().

## ◆ rb_eFloatDomainError

VALUE rb_eFloatDomainError

Definition at line 194 of file numeric.c.

Referenced by Init_Numeric(), rb_cstr_to_rat(), and VpException().

## ◆ rb_eZeroDivError

VALUE rb_eZeroDivError

Definition at line 193 of file numeric.c.

Referenced by Init_Numeric(), and rb_num_zerodiv().

## ◆ rb_infinity

const union bytesequence4_or_float rb_infinity = {{0x00, 0x00, 0x80, 0x7f}}

Definition at line 78 of file numeric.c.

## ◆ rb_nan

const union bytesequence4_or_float rb_nan = {{0x00, 0x00, 0xc0, 0x7f}}

Definition at line 85 of file numeric.c.