Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
|
#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) |
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 |
#define DEFINE_INT_SQRT | ( | rettype, | |
prefix, | |||
argtype | |||
) |
#define domain_error | ( | msg | ) | rb_raise(rb_eMathDomainError, "Numerical argument is out of domain - " #msg) |
#define FIT_SQRT_LONG | ( | n | ) | (((n)<SQRT_LONG_MAX)&&((n)>=-SQRT_LONG_MAX)) |
#define flo_eq rb_float_equal |
#define flo_eql rb_float_eql |
#define FLOAT_OUT_OF_RANGE | ( | val, | |
type | |||
) |
#define int_succ rb_int_succ |
#define LONG_MIN_MINUS_ONE_IS_LESS_THAN | ( | n | ) |
#define method_basic_p | ( | klass | ) | rb_method_basic_definition_p(klass, mid) |
#define num_clone rb_immutable_obj_clone |
#define NUMERR_NEGATIVE 2 |
#define NUMERR_TOOLARGE 3 |
#define NUMERR_TYPE 1 |
#define SQRT_LONG_MAX HALF_LONG_MSB |
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().
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.
VALUE rb_dbl_cmp | ( | double | a, |
double | b | ||
) |
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().
short rb_fix2short | ( | VALUE | val | ) |
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().
Definition at line 3060 of file numeric.c.
References RB_FIX2ULONG.
unsigned short rb_fix2ushort | ( | VALUE | val | ) |
Definition at line 4613 of file numeric.c.
References CHAR_BIT, FIX2LONG, FIXNUM_P, INT2FIX, rb_big_norm(), and rb_to_int().
Definition at line 1140 of file numeric.c.
References DBL2NUM, num, and RFLOAT_VALUE.
Referenced by rb_big_fdiv_double(), and rb_rational_div().
Definition at line 1804 of file numeric.c.
References isfinite, isinf(), isnan, num, Qfalse, Qtrue, and RFLOAT_VALUE.
Referenced by Init_Numeric().
Definition at line 1784 of file numeric.c.
References INT2FIX, isinf(), num, Qnil, and RFLOAT_VALUE.
Referenced by Init_Numeric().
Definition at line 1732 of file numeric.c.
References DBL2NUM, and RFLOAT_VALUE.
Referenced by Init_Numeric().
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().
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.
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().
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().
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().
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.
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().
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().
Definition at line 1041 of file numeric.c.
References DBL2NUM, and RFLOAT_VALUE.
Referenced by Init_Numeric().
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().
Definition at line 4826 of file numeric.c.
References FIXNUM_P, num, Qnil, rb_big_abs(), and T_BIGNUM.
Referenced by rb_rational_abs().
Definition at line 4436 of file numeric.c.
References FIXNUM_P, Qnil, rb_big_and(), and T_BIGNUM.
Referenced by Init_Numeric().
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().
Definition at line 3803 of file numeric.c.
References FIXNUM_P, Qnil, rb_big_div(), and T_BIGNUM.
Referenced by Init_Numeric().
Definition at line 3950 of file numeric.c.
References FIXNUM_P, Qnil, rb_big_divmod(), and T_BIGNUM.
Referenced by Init_Numeric().
Definition at line 4147 of file numeric.c.
References FIXNUM_P, Qnil, rb_big_eq(), and T_BIGNUM.
Referenced by Init_Numeric().
Definition at line 3748 of file numeric.c.
References DBL2NUM, Qnil, rb_int_fdiv_double(), and RB_INTEGER_TYPE_P.
Referenced by Init_Numeric().
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().
Definition at line 4276 of file numeric.c.
References FIXNUM_P, Qnil, rb_big_ge(), and T_BIGNUM.
Referenced by Init_Numeric().
Definition at line 4236 of file numeric.c.
References FIXNUM_P, Qnil, rb_big_gt(), and T_BIGNUM.
Referenced by Init_Numeric().
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().
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().
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().
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().
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().
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().
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().
Definition at line 4022 of file numeric.c.
Referenced by date_zone_to_diff(), rb_flt_rationalize(), and rb_str_format().
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().
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.
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().
Definition at line 3140 of file numeric.c.
References FIXABLE, FIXNUM_P, LONG2FIX, rb_eRangeError, rb_num2long(), and rb_raise().
Definition at line 3042 of file numeric.c.
References rb_num2long().
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().
short rb_num2short | ( | VALUE | val | ) |
Definition at line 3098 of file numeric.c.
References num, and rb_num2long().
Definition at line 3054 of file numeric.c.
References rb_num2ulong().
unsigned short rb_num2ushort | ( | VALUE | val | ) |
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().
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().
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().
Definition at line 474 of file numeric.c.
References FALSE, Qnil, rb_cmperr(), rb_funcall(), and UNREACHABLE_RETURN.
Referenced by rb_float_gt().
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.
Definition at line 319 of file numeric.c.
References num.
Referenced by rb_random_ulong_limited(), and rb_rational_pow().
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().
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().
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().
void rb_out_of_int | ( | SIGNED_VALUE | num | ) |
Definition at line 2969 of file numeric.c.
References num, PRIdVALUE, rb_eRangeError, and rb_raise().
double round | ( | double | x | ) |
double ruby_float_mod | ( | double | x, |
double | y | ||
) |
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().
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.
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().
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().
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().
VALUE rb_eFloatDomainError |
Definition at line 194 of file numeric.c.
Referenced by Init_Numeric(), rb_cstr_to_rat(), and VpException().
VALUE rb_eZeroDivError |
Definition at line 193 of file numeric.c.
Referenced by Init_Numeric(), and rb_num_zerodiv().
const union bytesequence4_or_float rb_infinity = {{0x00, 0x00, 0x80, 0x7f}} |
const union bytesequence4_or_float rb_nan = {{0x00, 0x00, 0xc0, 0x7f}} |