8#include "ruby/internal/config.h"
12# define _USE_MATH_DEFINES 1
20#include "internal/array.h"
21#include "internal/class.h"
22#include "internal/complex.h"
23#include "internal/math.h"
24#include "internal/numeric.h"
25#include "internal/object.h"
26#include "internal/rational.h"
27#include "ruby_assert.h"
29#define ZERO INT2FIX(0)
33#define RFLOAT_0 DBL2NUM(0)
40static ID id_abs, id_arg,
41 id_denominator, id_numerator,
42 id_real_p, id_i_real, id_i_imag,
43 id_finite_p, id_infinite_p, id_rationalize,
47#define id_negate idUMinus
57 return rb_funcall(x, id_##n, 0);\
62f_##n(VALUE x, VALUE y)\
64 return rb_funcall(x, id_##n, 1, y);\
67#define PRESERVE_SIGNEDZERO
73 LIKELY(rb_method_basic_definition_p(
rb_cInteger, idPLUS))) {
78 return rb_int_plus(x, y);
81 LIKELY(rb_method_basic_definition_p(
rb_cFloat, idPLUS))) {
84 return rb_float_plus(x, y);
87 LIKELY(rb_method_basic_definition_p(
rb_cRational, idPLUS))) {
90 return rb_rational_plus(x, y);
110 return RTEST(rb_int_gt(x, y));
113 return RTEST(rb_float_gt(x, y));
115 int const cmp = rb_cmpint(rb_rational_cmp(x, y), x, y);
125 LIKELY(rb_method_basic_definition_p(
rb_cInteger, idMULT))) {
126 if (FIXNUM_ZERO_P(y))
130 if (x == ONE)
return y;
131 if (y == ONE)
return x;
132 return rb_int_mul(x, y);
135 LIKELY(rb_method_basic_definition_p(
rb_cFloat, idMULT))) {
136 if (y == ONE)
return x;
137 return rb_float_mul(x, y);
140 LIKELY(rb_method_basic_definition_p(
rb_cRational, idMULT))) {
141 if (y == ONE)
return x;
142 return rb_rational_mul(x, y);
144 else if (LIKELY(rb_method_basic_definition_p(
CLASS_OF(x), idMULT))) {
145 if (y == ONE)
return x;
153 if (FIXNUM_ZERO_P(y) &&
154 LIKELY(rb_method_basic_definition_p(
CLASS_OF(x), idMINUS))) {
164 return rb_int_abs(x);
167 return rb_float_abs(x);
170 return rb_rational_abs(x);
173 return rb_complex_abs(x);
185 return numeric_arg(x);
191 return numeric_arg(x);
194 return rb_complex_arg(x);
203 return RRATIONAL(x)->num;
206 return rb_float_numerator(x);
212f_denominator(
VALUE x)
215 return RRATIONAL(x)->den;
218 return rb_float_denominator(x);
227 return rb_int_uminus(x);
230 return rb_float_uminus(x);
233 return rb_rational_uminus(x);
236 return rb_complex_uminus(x);
241static bool nucomp_real_p(
VALUE self);
256 return nucomp_real_p(x);
265 return rb_str_to_inum(x, 10, 0);
296 return rb_numeric_quo(x, y);
298 return rb_float_div(x, y);
300 return rb_numeric_quo(x, y);
302 return rb_funcallv(x, id_quo, 1, &y);
309 return INT_NEGATIVE_P(x);
313 return INT_NEGATIVE_P(RRATIONAL(x)->num);
314 return rb_num_negative_p(x);
317#define f_positive_p(x) (!f_negative_p(x))
323 return FLOAT_ZERO_P(x);
326 return FIXNUM_ZERO_P(x);
329 const VALUE num = RRATIONAL(x)->num;
330 return FIXNUM_ZERO_P(num);
335#define f_nonzero_p(x) (!f_zero_p(x))
338always_finite_type_p(
VALUE x)
348 if (always_finite_type_p(x)) {
354 return RTEST(rb_funcallv(x, id_finite_p, 0, 0));
360 if (always_finite_type_p(x)) {
366 return RTEST(rb_funcallv(x, id_infinite_p, 0, 0));
381#define k_exact_p(x) (!RB_FLOAT_TYPE_P(x))
383#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
386 struct RComplex *dat = RCOMPLEX(x)
388#define get_dat2(x,y) \
389 struct RComplex *adat = RCOMPLEX(x), *bdat = RCOMPLEX(y)
396 RCOMPLEX_SET_REAL(obj, real);
397 RCOMPLEX_SET_IMAG(obj, imag);
404nucomp_s_alloc(
VALUE klass)
406 return nucomp_s_new_internal(klass, ZERO, ZERO);
413 return nucomp_s_new_internal(klass, x, ZERO);
421 return nucomp_s_new_internal(klass, x, y);
424WARN_UNUSED_RESULT(
inline static VALUE nucomp_real_check(
VALUE num));
426nucomp_real_check(
VALUE num)
432 VALUE real = RCOMPLEX(num)->real;
436 if (!k_numeric_p(num) || !f_real_p(num))
445 int complex_r, complex_i;
448 if (!complex_r && !complex_i) {
449 return nucomp_s_new_internal(klass, real, imag);
451 else if (!complex_r) {
454 return nucomp_s_new_internal(klass,
455 f_sub(real, dat->imag),
456 f_add(ZERO, dat->real));
458 else if (!complex_i) {
461 return nucomp_s_new_internal(klass,
463 f_add(dat->imag, imag));
466 get_dat2(real, imag);
468 return nucomp_s_new_internal(klass,
469 f_sub(adat->real, bdat->imag),
470 f_add(adat->imag, bdat->real));
484nucomp_s_new(
int argc,
VALUE *argv,
VALUE klass)
490 real = nucomp_real_check(real);
494 real = nucomp_real_check(real);
495 imag = nucomp_real_check(imag);
499 return nucomp_s_new_internal(klass, real, imag);
508 y = f_add(dat->imag, y);
510 return nucomp_s_canonicalize_internal(klass, x, y);
553nucomp_f_complex(
int argc,
VALUE *argv,
VALUE klass)
558 if (
rb_scan_args(argc, argv,
"11:", &a1, &a2, &opts) == 1) {
562 raise = rb_opts_exception_p(opts, raise);
572m_##n##_bang(VALUE x)\
574 return rb_math_##n(x);\
584 return rb_math_log(1, &x);
594 return m_cos_bang(x);
598 f_mul(m_cos_bang(dat->real),
599 m_cosh_bang(dat->imag)),
600 f_mul(f_negate(m_sin_bang(dat->real)),
601 m_sinh_bang(dat->imag)));
609 return m_sin_bang(x);
613 f_mul(m_sin_bang(dat->real),
614 m_cosh_bang(dat->imag)),
615 f_mul(m_cos_bang(dat->real),
616 m_sinh_bang(dat->imag)));
623 if (f_zero_p(x) || f_zero_p(y)) {
624 return nucomp_s_new_internal(klass, x, RFLOAT_0);
632 else if (arg == M_PI_2) {
636 else if (arg == M_PI_2+M_PI) {
642 const double real = abs * cos(arg), imag = abs * sin(arg);
647 const double ax = sin(arg), ay = cos(arg);
651 return nucomp_s_new_internal(klass, x, y);
653 return nucomp_s_canonicalize_internal(klass,
661 x = nucomp_real_check(x);
662 y = nucomp_real_check(y);
663 return f_complex_polar_real(klass, x, y);
667# define cospi(x) __cospi(x)
669# define cospi(x) cos((x) * M_PI)
672# define sinpi(x) __sinpi(x)
674# define sinpi(x) sin((x) * M_PI)
678rb_dbl_complex_new_polar_pi(
double abs,
double ang)
681 const double fr = modf(ang, &fi);
682 int pos = fr == +0.5;
684 if (pos || fr == -0.5) {
685 if ((modf(fi / 2.0, &fi) != fr) ^ pos) abs = -abs;
686 return rb_complex_new(RFLOAT_0,
DBL2NUM(abs));
688 else if (fr == 0.0) {
689 if (modf(fi / 2.0, &fi) != 0.0) abs = -abs;
693 const double real = abs * cospi(ang), imag = abs * sinpi(ang);
710nucomp_s_polar(
int argc,
VALUE *argv,
VALUE klass)
715 abs = nucomp_real_check(abs);
717 arg = nucomp_real_check(arg);
722 return f_complex_polar_real(klass, abs, arg);
770 return f_complex_new2(
CLASS_OF(self),
771 f_negate(dat->real), f_negate(dat->imag));
792 get_dat2(self, other);
794 real = f_add(adat->real, bdat->real);
795 imag = f_add(adat->imag, bdat->imag);
797 return f_complex_new2(
CLASS_OF(self), real, imag);
799 if (k_numeric_p(other) && f_real_p(other)) {
802 return f_complex_new2(
CLASS_OF(self),
803 f_add(dat->real, other), dat->imag);
826 get_dat2(self, other);
828 real = f_sub(adat->real, bdat->real);
829 imag = f_sub(adat->imag, bdat->imag);
831 return f_complex_new2(
CLASS_OF(self), real, imag);
833 if (k_numeric_p(other) && f_real_p(other)) {
836 return f_complex_new2(
CLASS_OF(self),
837 f_sub(dat->real, other), dat->imag);
858 bool arzero = f_zero_p(areal);
859 bool aizero = f_zero_p(aimag);
860 bool brzero = f_zero_p(breal);
861 bool bizero = f_zero_p(bimag);
862 *real = f_sub(safe_mul(areal, breal, arzero, brzero),
863 safe_mul(aimag, bimag, aizero, bizero));
864 *imag = f_add(safe_mul(areal, bimag, arzero, bizero),
865 safe_mul(aimag, breal, aizero, brzero));
885 get_dat2(self, other);
887 comp_mul(adat->real, adat->imag, bdat->real, bdat->imag, &real, &imag);
889 return f_complex_new2(
CLASS_OF(self), real, imag);
891 if (k_numeric_p(other) && f_real_p(other)) {
894 return f_complex_new2(
CLASS_OF(self),
895 f_mul(dat->real, other),
896 f_mul(dat->imag, other));
908 get_dat2(self, other);
913 if (f_gt_p(f_abs(bdat->real), f_abs(bdat->imag))) {
914 r = (*func)(bdat->imag, bdat->real);
915 n = f_mul(bdat->real, f_add(ONE, f_mul(r, r)));
916 x = (*func)(f_add(adat->real, f_mul(adat->imag, r)), n);
917 y = (*func)(f_sub(adat->imag, f_mul(adat->real, r)), n);
920 r = (*func)(bdat->real, bdat->imag);
921 n = f_mul(bdat->imag, f_add(ONE, f_mul(r, r)));
922 x = (*func)(f_add(f_mul(adat->real, r), adat->imag), n);
923 y = (*func)(f_sub(f_mul(adat->imag, r), adat->real), n);
926 x = rb_rational_canonicalize(x);
927 y = rb_rational_canonicalize(y);
929 return f_complex_new2(
CLASS_OF(self), x, y);
931 if (k_numeric_p(other) && f_real_p(other)) {
934 x = rb_rational_canonicalize((*func)(dat->real, other));
935 y = rb_rational_canonicalize((*func)(dat->imag, other));
936 return f_complex_new2(
CLASS_OF(self), x, y);
941#define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
959 return f_divide(self, other, f_quo, id_quo);
962#define nucomp_quo rb_complex_div
975 return f_divide(self, other, f_fdiv, id_fdiv);
981 return f_quo(ONE, x);
996 if (k_numeric_p(other) && k_exact_zero_p(other))
997 return f_complex_new_bang1(
CLASS_OF(self), ONE);
1000 other = RRATIONAL(other)->num;
1005 if (k_exact_zero_p(dat->imag))
1010 VALUE r, theta, nr, ntheta;
1015 theta = f_arg(self);
1017 nr = m_exp_bang(f_sub(f_mul(dat->real, m_log_bang(r)),
1018 f_mul(dat->imag, theta)));
1019 ntheta = f_add(f_mul(theta, dat->real),
1020 f_mul(dat->imag, m_log_bang(r)));
1021 return f_complex_polar(
CLASS_OF(self), nr, ntheta);
1026 return nucomp_s_new_internal(
CLASS_OF(self), ONE, ZERO);
1029 self = f_reciprocal(self);
1030 other = rb_int_uminus(other);
1035 VALUE xr = dat->real, xi = dat->imag, zr = xr, zi = xi;
1038 zr = rb_num_pow(zr, other);
1040 else if (f_zero_p(xr)) {
1041 zi = rb_num_pow(zi, other);
1042 if (n & 2) zi = f_negate(zi);
1053 for (; q = n / 2, r = n % 2, r == 0; n = q) {
1054 VALUE tmp = f_sub(f_mul(xr, xr), f_mul(xi, xi));
1055 xi = f_mul(f_mul(TWO, xr), xi);
1058 comp_mul(zr, zi, xr, xi, &zr, &zi);
1061 return nucomp_s_new_internal(
CLASS_OF(self), zr, zi);
1064 if (k_numeric_p(other) && f_real_p(other)) {
1067 if (RB_BIGNUM_TYPE_P(other))
1068 rb_warn(
"in a**b, b may be too big");
1071 theta = f_arg(self);
1073 return f_complex_polar(
CLASS_OF(self), f_expt(r, other),
1074 f_mul(theta, other));
1095 get_dat2(self, other);
1097 return RBOOL(f_eqeq_p(adat->real, bdat->real) &&
1098 f_eqeq_p(adat->imag, bdat->imag));
1100 if (k_numeric_p(other) && f_real_p(other)) {
1103 return RBOOL(f_eqeq_p(dat->real, other) && f_zero_p(dat->imag));
1105 return RBOOL(f_eqeq_p(other, self));
1109nucomp_real_p(
VALUE self)
1112 return f_zero_p(dat->imag);
1132 if (!k_numeric_p(other)) {
1135 if (!nucomp_real_p(self)) {
1139 if (nucomp_real_p(other)) {
1140 get_dat2(self, other);
1141 return rb_funcall(adat->real, idCmp, 1, bdat->real);
1146 if (f_real_p(other)) {
1147 return rb_funcall(dat->real, idCmp, 1, other);
1161 return rb_assoc_new(other, self);
1162 if (k_numeric_p(other) && f_real_p(other))
1163 return rb_assoc_new(f_complex_new_bang1(
CLASS_OF(self), other), self);
1185 if (f_zero_p(dat->real)) {
1186 VALUE a = f_abs(dat->imag);
1191 if (f_zero_p(dat->imag)) {
1192 VALUE a = f_abs(dat->real);
1197 return rb_math_hypot(dat->real, dat->imag);
1210nucomp_abs2(
VALUE self)
1213 return f_add(f_mul(dat->real, dat->real),
1214 f_mul(dat->imag, dat->imag));
1231 return rb_math_atan2(dat->imag, dat->real);
1244nucomp_rect(
VALUE self)
1247 return rb_assoc_new(dat->real, dat->imag);
1259nucomp_polar(
VALUE self)
1261 return rb_assoc_new(f_abs(self), f_arg(self));
1277 return f_complex_new2(
CLASS_OF(self), dat->real, f_negate(dat->imag));
1288nucomp_real_p_m(
VALUE self)
1302nucomp_denominator(
VALUE self)
1305 return rb_lcm(f_denominator(dat->real), f_denominator(dat->imag));
1327nucomp_numerator(
VALUE self)
1333 cd = nucomp_denominator(self);
1334 return f_complex_new2(
CLASS_OF(self),
1335 f_mul(f_numerator(dat->real),
1336 f_div(cd, f_denominator(dat->real))),
1337 f_mul(f_numerator(dat->imag),
1338 f_div(cd, f_denominator(dat->imag))));
1343rb_complex_hash(
VALUE self)
1349 n = rb_hash(dat->real);
1351 n = rb_hash(dat->imag);
1358nucomp_hash(
VALUE self)
1360 return ST2FIX(rb_complex_hash(self));
1368 get_dat2(self, other);
1372 f_eqeq_p(self, other));
1383 return !isnan(f) && signbit(f);
1385 return f_negative_p(x);
1389f_tpositive_p(
VALUE x)
1391 return !f_signbit(x);
1402 impos = f_tpositive_p(dat->imag);
1404 s = (*func)(dat->real);
1428nucomp_to_s(
VALUE self)
1446nucomp_inspect(
VALUE self)
1457#define FINITE_TYPE_P(v) (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))
1467rb_complex_finite_p(
VALUE self)
1471 return RBOOL(f_finite_p(dat->real) && f_finite_p(dat->imag));
1487rb_complex_infinite_p(
VALUE self)
1491 if (!f_infinite_p(dat->real) && !f_infinite_p(dat->imag)) {
1499nucomp_dumper(
VALUE self)
1510 RCOMPLEX_SET_REAL(dat,
rb_ivar_get(a, id_i_real));
1511 RCOMPLEX_SET_IMAG(dat,
rb_ivar_get(a, id_i_imag));
1519nucomp_marshal_dump(
VALUE self)
1524 a = rb_assoc_new(dat->real, dat->imag);
1550 return nucomp_s_canonicalize_internal(
rb_cComplex, x, y);
1562 return rb_complex_new_polar(x, y);
1575rb_dbl_complex_new(
double real,
double imag)
1592nucomp_to_i(
VALUE self)
1596 if (!k_exact_zero_p(dat->imag)) {
1600 return f_to_i(dat->real);
1615nucomp_to_f(
VALUE self)
1619 if (!k_exact_zero_p(dat->imag)) {
1623 return f_to_f(dat->real);
1640nucomp_to_r(
VALUE self)
1644 if (!k_exact_zero_p(dat->imag)) {
1648 return f_to_r(dat->real);
1665nucomp_rationalize(
int argc,
VALUE *argv,
VALUE self)
1671 if (!k_exact_zero_p(dat->imag)) {
1675 return rb_funcallv(dat->real, id_rationalize, argc, argv);
1688nucomp_to_c(
VALUE self)
1700nilclass_to_c(
VALUE self)
1712numeric_to_c(
VALUE self)
1720 return (c ==
'-' || c ==
'+');
1724read_sign(
const char **s,
1740 return isdigit((
unsigned char)c);
1744read_digits(
const char **s,
int strict,
1749 if (!isdecimal(**s))
1752 while (isdecimal(**s) || **s ==
'_') {
1755 if (strict)
return 0;
1770 }
while (**s ==
'_');
1777 return (c ==
'e' || c ==
'E');
1781read_num(
const char **s,
int strict,
1785 if (!read_digits(s, strict, b))
1793 if (!read_digits(s, strict, b)) {
1799 if (islettere(**s)) {
1804 if (!read_digits(s, strict, b)) {
1813read_den(
const char **s,
int strict,
1816 if (!read_digits(s, strict, b))
1822read_rat_nos(
const char **s,
int strict,
1825 if (!read_num(s, strict, b))
1831 if (!read_den(s, strict, b)) {
1840read_rat(
const char **s,
int strict,
1844 if (!read_rat_nos(s, strict, b))
1852 return (c ==
'i' || c ==
'I' ||
1853 c ==
'j' || c ==
'J');
1860 return rb_cstr_to_rat(s, 0);
1861 if (strpbrk(s,
".eE"))
1863 return rb_cstr_to_inum(s, 10, 0);
1867read_comp(
const char **s,
int strict,
1868 VALUE *ret,
char **b)
1876 sign = read_sign(s, b);
1878 if (isimagunit(**s)) {
1880 num =
INT2FIX((sign ==
'-') ? -1 : + 1);
1885 if (!read_rat_nos(s, strict, b)) {
1894 if (isimagunit(**s)) {
1905 st = read_rat(s, strict, b);
1907 if (strlen(bb) < 1 ||
1908 !isdecimal(*(bb + strlen(bb) - 1))) {
1913 *ret = rb_complex_new_polar(num, num2);
1922 sign = read_sign(s, b);
1923 if (isimagunit(**s))
1924 num2 =
INT2FIX((sign ==
'-') ? -1 : + 1);
1926 if (!read_rat_nos(s, strict, b)) {
1933 if (!isimagunit(**s)) {
1949skip_ws(
const char **s)
1951 while (isspace((
unsigned char)**s))
1956parse_comp(
const char *s,
int strict,
VALUE *num)
1962 buf =
ALLOCV_N(
char, tmp, strlen(s) + 1);
1966 if (!read_comp(&s, strict, num, &b)) {
1982string_to_c_strict(
VALUE self,
int raise)
1992 if (!raise)
return Qnil;
2005 if (!parse_comp(s, 1, &num)) {
2006 if (!raise)
return Qnil;
2044string_to_c(
VALUE self)
2062 (void)parse_comp(s, 0, &num);
2068to_complex(
VALUE val)
2077 if (!raise)
return Qnil;
2082 a1 = string_to_c_strict(a1, raise);
2087 a2 = string_to_c_strict(a2, raise);
2095 if (k_exact_zero_p(dat->imag))
2104 if (k_exact_zero_p(dat->imag))
2110 if (UNDEF_P(a2) || (k_exact_zero_p(a2)))
2115 if (k_numeric_p(a1) && !f_real_p(a1))
2118 if (!k_numeric_p(a1)) {
2120 return rb_protect(to_complex, a1, NULL);
2121 return to_complex(a1);
2125 if ((k_numeric_p(a1) && k_numeric_p(a2)) &&
2126 (!f_real_p(a1) || !f_real_p(a2)))
2146 return nucomp_s_new(argc, argv2, klass);
2151nucomp_s_convert(
int argc,
VALUE *argv,
VALUE klass)
2159 return nucomp_convert(klass, a1, a2, TRUE);
2169numeric_abs2(
VALUE self)
2171 return f_mul(self, self);
2183numeric_arg(
VALUE self)
2185 if (f_positive_p(self))
2198numeric_rect(
VALUE self)
2200 return rb_assoc_new(self,
INT2FIX(0));
2210numeric_polar(
VALUE self)
2215 abs = rb_int_abs(self);
2216 arg = numeric_arg(self);
2219 abs = rb_float_abs(self);
2220 arg = float_arg(self);
2223 abs = rb_rational_abs(self);
2224 arg = numeric_arg(self);
2230 return rb_assoc_new(abs, arg);
2242float_arg(
VALUE self)
2246 if (f_tpositive_p(self))
2417 rb_gc_register_mark_object(RFLOAT_0 =
DBL2NUM(0.0));
static int rb_isdigit(int c)
Our own locale-insensitive version of isdigit(3).
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define T_COMPLEX
Old name of RUBY_T_COMPLEX.
#define NEWOBJ_OF
Old name of RB_NEWOBJ_OF.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define OBJ_FREEZE_RAW
Old name of RB_OBJ_FREEZE_RAW.
#define CLASS_OF
Old name of rb_class_of.
#define LONG2FIX
Old name of RB_INT2FIX.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define NUM2DBL
Old name of rb_num2dbl.
VALUE rb_complex_polar(VALUE x, VALUE y)
Old name of rb_complex_new_polar.
#define rb_usascii_str_new2
Old name of rb_usascii_str_new_cstr.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define ST2FIX
Old name of RB_ST2FIX.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define ALLOCV_N
Old name of RB_ALLOCV_N.
#define FL_WB_PROTECTED
Old name of RUBY_FL_WB_PROTECTED.
#define DBL2NUM
Old name of rb_float_new.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eTypeError
TypeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_cRational
Rational class.
VALUE rb_convert_type(VALUE val, int type, const char *name, const char *mid)
Converts an object into another type.
VALUE rb_cComplex
Complex class.
VALUE rb_mMath
Math module.
VALUE rb_cInteger
Module class.
VALUE rb_cNilClass
NilClass class.
double rb_str_to_dbl(VALUE str, int mode)
Identical to rb_cstr_to_dbl(), except it accepts a Ruby's string instead of C's.
VALUE rb_cNumeric
Numeric class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
double rb_cstr_to_dbl(const char *str, int mode)
Converts a textual representation of a real number into a numeric, which is the nearest value that th...
VALUE rb_mComparable
Comparable module.
VALUE rb_cFloat
Float class.
VALUE rb_String(VALUE val)
This is the logic behind Kernel#String.
VALUE rb_cString
String class.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
#define rb_complex_new2(x, y)
Just another name of rb_complex_new.
#define rb_complex_new1(x)
Shorthand of x+0i.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
VALUE rb_num_coerce_cmp(VALUE lhs, VALUE rhs, ID op)
Identical to rb_num_coerce_bin(), except for return values.
VALUE rb_num_coerce_bin(VALUE lhs, VALUE rhs, ID op)
Coerced binary operation.
st_index_t rb_memhash(const void *ptr, long len)
This is a universal hash function.
void rb_str_modify(VALUE str)
Declares that the string is about to be modified.
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
void rb_define_const(VALUE klass, const char *name, VALUE val)
Defines a Ruby level constant under a namespace.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
void rb_copy_generic_ivar(VALUE clone, VALUE obj)
Copies the list of instance variables.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RGENGC_WB_PROTECTED_COMPLEX
This is a compile-time flag to enable/disable write barrier for struct RComplex.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
#define RTEST
This is an old name of RB_TEST.
Internal header for Complex.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_FLOAT_TYPE_P(VALUE obj)
Queries if the object is an instance of rb_cFloat.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.