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/error.h"
24#include "internal/math.h"
25#include "internal/numeric.h"
26#include "internal/object.h"
27#include "internal/rational.h"
28#include "internal/string.h"
29#include "ruby_assert.h"
31#define ZERO INT2FIX(0)
35#define RFLOAT_0 DBL2NUM(0)
42static ID id_abs, id_arg,
43 id_real_p, id_i_real, id_i_imag,
44 id_finite_p, id_infinite_p, id_rationalize,
48#define id_negate idUMinus
54#define PRESERVE_SIGNEDZERO
65 return rb_int_plus(x, y);
71 return rb_float_plus(x, y);
77 return rb_rational_plus(x, y);
97 return RTEST(rb_int_gt(x, y));
100 return RTEST(rb_float_gt(x, y));
102 int const cmp = rb_cmpint(rb_rational_cmp(x, y), x, y);
113 if (FIXNUM_ZERO_P(y))
117 if (x == ONE)
return y;
118 if (y == ONE)
return x;
119 return rb_int_mul(x, y);
123 if (y == ONE)
return x;
124 return rb_float_mul(x, y);
128 if (y == ONE)
return x;
129 return rb_rational_mul(x, y);
132 if (y == ONE)
return x;
140 if (FIXNUM_ZERO_P(y) &&
151 return rb_int_abs(x);
154 return rb_float_abs(x);
157 return rb_rational_abs(x);
160 return rb_complex_abs(x);
172 return numeric_arg(x);
178 return numeric_arg(x);
181 return rb_complex_arg(x);
190 return RRATIONAL(x)->num;
193 return rb_float_numerator(x);
199f_denominator(
VALUE x)
202 return RRATIONAL(x)->den;
205 return rb_float_denominator(x);
214 return rb_int_uminus(x);
217 return rb_float_uminus(x);
220 return rb_rational_uminus(x);
223 return rb_complex_uminus(x);
228static bool nucomp_real_p(
VALUE self);
243 return nucomp_real_p(x);
252 return rb_str_to_inum(x, 10, 0);
278 return rb_int_fdiv(x, y);
280 return rb_float_div(x, y);
282 return rb_rational_fdiv(x, y);
291 return rb_numeric_quo(x, y);
293 return rb_float_div(x, y);
295 return rb_numeric_quo(x, y);
304 return INT_NEGATIVE_P(x);
308 return INT_NEGATIVE_P(RRATIONAL(x)->num);
309 return rb_num_negative_p(x);
312#define f_positive_p(x) (!f_negative_p(x))
315always_finite_type_p(
VALUE x)
325 if (always_finite_type_p(x)) {
337 if (always_finite_type_p(x)) {
358#define k_exact_p(x) (!RB_FLOAT_TYPE_P(x))
360#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
363 struct RComplex *dat = RCOMPLEX(x)
365#define get_dat2(x,y) \
366 struct RComplex *adat = RCOMPLEX(x), *bdat = RCOMPLEX(y)
373 RCOMPLEX_SET_REAL(obj, real);
374 RCOMPLEX_SET_IMAG(obj, imag);
381nucomp_s_alloc(
VALUE klass)
383 return nucomp_s_new_internal(klass, ZERO, ZERO);
390 return nucomp_s_new_internal(klass, x, ZERO);
398 return nucomp_s_new_internal(klass, x, y);
401WARN_UNUSED_RESULT(
inline static VALUE nucomp_real_check(
VALUE num));
403nucomp_real_check(
VALUE num)
409 VALUE real = RCOMPLEX(num)->real;
413 if (!k_numeric_p(num) || !f_real_p(num))
422 int complex_r, complex_i;
425 if (!complex_r && !complex_i) {
426 return nucomp_s_new_internal(klass, real, imag);
428 else if (!complex_r) {
431 return nucomp_s_new_internal(klass,
432 f_sub(real, dat->imag),
433 f_add(ZERO, dat->real));
435 else if (!complex_i) {
438 return nucomp_s_new_internal(klass,
440 f_add(dat->imag, imag));
443 get_dat2(real, imag);
445 return nucomp_s_new_internal(klass,
446 f_sub(adat->real, bdat->imag),
447 f_add(adat->imag, bdat->real));
468nucomp_s_new(
int argc,
VALUE *argv,
VALUE klass)
474 real = nucomp_real_check(real);
478 real = nucomp_real_check(real);
479 imag = nucomp_real_check(imag);
483 return nucomp_s_new_internal(klass, real, imag);
492 y = f_add(dat->imag, y);
494 return nucomp_s_canonicalize_internal(klass, x, y);
552nucomp_f_complex(
int argc,
VALUE *argv,
VALUE klass)
557 if (
rb_scan_args(argc, argv,
"11:", &a1, &a2, &opts) == 1) {
561 raise = rb_opts_exception_p(opts, raise);
571m_##n##_bang(VALUE x)\
573 return rb_math_##n(x);\
583 return rb_math_log(1, &x);
593 return m_cos_bang(x);
597 f_mul(m_cos_bang(dat->real),
598 m_cosh_bang(dat->imag)),
599 f_mul(f_negate(m_sin_bang(dat->real)),
600 m_sinh_bang(dat->imag)));
608 return m_sin_bang(x);
612 f_mul(m_sin_bang(dat->real),
613 m_cosh_bang(dat->imag)),
614 f_mul(m_cos_bang(dat->real),
615 m_sinh_bang(dat->imag)));
622 if (f_zero_p(x) || f_zero_p(y)) {
623 return nucomp_s_new_internal(klass, x, RFLOAT_0);
631 else if (arg == M_PI_2) {
635 else if (arg == M_PI_2+M_PI) {
641 const double real = abs * cos(arg), imag = abs * sin(arg);
646 const double ax = sin(arg), ay = cos(arg);
650 return nucomp_s_new_internal(klass, x, y);
652 return nucomp_s_canonicalize_internal(klass,
660 x = nucomp_real_check(x);
661 y = nucomp_real_check(y);
662 return f_complex_polar_real(klass, x, y);
666# define cospi(x) __cospi(x)
668# define cospi(x) cos((x) * M_PI)
671# define sinpi(x) __sinpi(x)
673# define sinpi(x) sin((x) * M_PI)
677rb_dbl_complex_new_polar_pi(
double abs,
double ang)
680 const double fr = modf(ang, &fi);
681 int pos = fr == +0.5;
683 if (pos || fr == -0.5) {
684 if ((modf(fi / 2.0, &fi) != fr) ^ pos) abs = -abs;
685 return rb_complex_new(RFLOAT_0,
DBL2NUM(abs));
687 else if (fr == 0.0) {
688 if (modf(fi / 2.0, &fi) != 0.0) abs = -abs;
692 const double real = abs * cospi(ang), imag = abs * sinpi(ang);
714nucomp_s_polar(
int argc,
VALUE *argv,
VALUE klass)
719 abs = nucomp_real_check(abs);
721 arg = nucomp_real_check(arg);
726 return f_complex_polar_real(klass, abs, arg);
789 return f_complex_new2(
CLASS_OF(self),
790 f_negate(dat->real), f_negate(dat->imag));
821 get_dat2(self, other);
823 real = f_add(adat->real, bdat->real);
824 imag = f_add(adat->imag, bdat->imag);
826 return f_complex_new2(
CLASS_OF(self), real, imag);
828 if (k_numeric_p(other) && f_real_p(other)) {
831 return f_complex_new2(
CLASS_OF(self),
832 f_add(dat->real, other), dat->imag);
856 get_dat2(self, other);
858 real = f_sub(adat->real, bdat->real);
859 imag = f_sub(adat->imag, bdat->imag);
861 return f_complex_new2(
CLASS_OF(self), real, imag);
863 if (k_numeric_p(other) && f_real_p(other)) {
866 return f_complex_new2(
CLASS_OF(self),
867 f_sub(dat->real, other), dat->imag);
888 bool arzero = f_zero_p(areal);
889 bool aizero = f_zero_p(aimag);
890 bool brzero = f_zero_p(breal);
891 bool bizero = f_zero_p(bimag);
892 *real = f_sub(safe_mul(areal, breal, arzero, brzero),
893 safe_mul(aimag, bimag, aizero, bizero));
894 *imag = f_add(safe_mul(areal, bimag, arzero, bizero),
895 safe_mul(aimag, breal, aizero, brzero));
917 get_dat2(self, other);
919 comp_mul(adat->real, adat->imag, bdat->real, bdat->imag, &real, &imag);
921 return f_complex_new2(
CLASS_OF(self), real, imag);
923 if (k_numeric_p(other) && f_real_p(other)) {
926 return f_complex_new2(
CLASS_OF(self),
927 f_mul(dat->real, other),
928 f_mul(dat->imag, other));
940 get_dat2(self, other);
945 if (f_gt_p(f_abs(bdat->real), f_abs(bdat->imag))) {
946 r = (*func)(bdat->imag, bdat->real);
947 n = f_mul(bdat->real, f_add(ONE, f_mul(r, r)));
948 x = (*func)(f_add(adat->real, f_mul(adat->imag, r)), n);
949 y = (*func)(f_sub(adat->imag, f_mul(adat->real, r)), n);
952 r = (*func)(bdat->real, bdat->imag);
953 n = f_mul(bdat->imag, f_add(ONE, f_mul(r, r)));
954 x = (*func)(f_add(f_mul(adat->real, r), adat->imag), n);
955 y = (*func)(f_sub(f_mul(adat->imag, r), adat->real), n);
958 x = rb_rational_canonicalize(x);
959 y = rb_rational_canonicalize(y);
961 return f_complex_new2(
CLASS_OF(self), x, y);
963 if (k_numeric_p(other) && f_real_p(other)) {
966 x = rb_rational_canonicalize((*func)(dat->real, other));
967 y = rb_rational_canonicalize((*func)(dat->imag, other));
968 return f_complex_new2(
CLASS_OF(self), x, y);
973#define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
991 return f_divide(self, other, f_quo, id_quo);
994#define nucomp_quo rb_complex_div
1008 return f_divide(self, other, f_fdiv, id_fdiv);
1012f_reciprocal(
VALUE x)
1014 return f_quo(ONE, x);
1029complex_pow_for_special_angle(
VALUE self,
VALUE other)
1038 if (f_zero_p(dat->imag)) {
1042 else if (f_zero_p(dat->real)) {
1046 else if (f_eqeq_p(dat->real, dat->imag)) {
1050 else if (f_eqeq_p(dat->real, f_negate(dat->imag))) {
1058 if (UNDEF_P(x))
return x;
1060 if (f_negative_p(x)) {
1067 zx = rb_num_pow(x, other);
1072 rb_int_div(other, TWO)
1074 if (rb_int_odd_p(other)) {
1078 static const int dirs[][2] = {
1079 {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}
1084 switch (dirs[z_dir][0]) {
1085 case 0: zr = zero_for(zx);
break;
1086 case 1: zr = zx;
break;
1087 case -1: zr = f_negate(zx);
break;
1089 switch (dirs[z_dir][1]) {
1090 case 0: zi = zero_for(zx);
break;
1091 case 1: zi = zx;
break;
1092 case -1: zi = f_negate(zx);
break;
1094 return nucomp_s_new_internal(
CLASS_OF(self), zr, zi);
1111 if (k_numeric_p(other) && k_exact_zero_p(other))
1112 return f_complex_new_bang1(
CLASS_OF(self), ONE);
1115 other = RRATIONAL(other)->num;
1120 if (k_exact_zero_p(dat->imag))
1126 return nucomp_s_new_internal(
CLASS_OF(self), dat->real, dat->imag);
1129 VALUE result = complex_pow_for_special_angle(self, other);
1130 if (!UNDEF_P(result))
return result;
1133 VALUE r, theta, nr, ntheta;
1138 theta = f_arg(self);
1140 nr = m_exp_bang(f_sub(f_mul(dat->real, m_log_bang(r)),
1141 f_mul(dat->imag, theta)));
1142 ntheta = f_add(f_mul(theta, dat->real),
1143 f_mul(dat->imag, m_log_bang(r)));
1144 return f_complex_polar(
CLASS_OF(self), nr, ntheta);
1149 return nucomp_s_new_internal(
CLASS_OF(self), ONE, ZERO);
1152 self = f_reciprocal(self);
1153 other = rb_int_uminus(other);
1158 VALUE xr = dat->real, xi = dat->imag, zr = xr, zi = xi;
1161 zr = rb_num_pow(zr, other);
1163 else if (f_zero_p(xr)) {
1164 zi = rb_num_pow(zi, other);
1165 if (n & 2) zi = f_negate(zi);
1176 for (; q = n / 2, r = n % 2, r == 0; n = q) {
1177 VALUE tmp = f_sub(f_mul(xr, xr), f_mul(xi, xi));
1178 xi = f_mul(f_mul(TWO, xr), xi);
1181 comp_mul(zr, zi, xr, xi, &zr, &zi);
1184 return nucomp_s_new_internal(
CLASS_OF(self), zr, zi);
1187 if (k_numeric_p(other) && f_real_p(other)) {
1190 if (RB_BIGNUM_TYPE_P(other))
1191 rb_warn(
"in a**b, b may be too big");
1193 r = rb_num_pow(f_abs(self), other);
1194 theta = f_mul(f_arg(self), other);
1196 return f_complex_polar(
CLASS_OF(self), r, theta);
1215 get_dat2(self, other);
1217 return RBOOL(f_eqeq_p(adat->real, bdat->real) &&
1218 f_eqeq_p(adat->imag, bdat->imag));
1220 if (k_numeric_p(other) && f_real_p(other)) {
1223 return RBOOL(f_eqeq_p(dat->real, other) && f_zero_p(dat->imag));
1225 return RBOOL(f_eqeq_p(other, self));
1229nucomp_real_p(
VALUE self)
1232 return f_zero_p(dat->imag);
1265 if (!k_numeric_p(other)) {
1268 if (!nucomp_real_p(self)) {
1272 if (nucomp_real_p(other)) {
1273 get_dat2(self, other);
1274 return rb_funcall(adat->real, idCmp, 1, bdat->real);
1279 if (f_real_p(other)) {
1280 return rb_funcall(dat->real, idCmp, 1, other);
1295 if (k_numeric_p(other) && f_real_p(other))
1298 rb_raise(
rb_eTypeError,
"%"PRIsVALUE
" can't be coerced into %"PRIsVALUE,
1324 if (f_zero_p(dat->real)) {
1325 VALUE a = f_abs(dat->imag);
1330 if (f_zero_p(dat->imag)) {
1331 VALUE a = f_abs(dat->real);
1336 return rb_math_hypot(dat->real, dat->imag);
1356nucomp_abs2(
VALUE self)
1359 return f_add(f_mul(dat->real, dat->real),
1360 f_mul(dat->imag, dat->imag));
1383 return rb_math_atan2(dat->imag, dat->real);
1406nucomp_rect(
VALUE self)
1430nucomp_polar(
VALUE self)
1448 return f_complex_new2(
CLASS_OF(self), dat->real, f_negate(dat->imag));
1458nucomp_real_p_m(
VALUE self)
1478nucomp_denominator(
VALUE self)
1481 return rb_lcm(f_denominator(dat->real), f_denominator(dat->imag));
1505nucomp_numerator(
VALUE self)
1511 cd = nucomp_denominator(self);
1512 return f_complex_new2(
CLASS_OF(self),
1513 f_mul(f_numerator(dat->real),
1514 f_div(cd, f_denominator(dat->real))),
1515 f_mul(f_numerator(dat->imag),
1516 f_div(cd, f_denominator(dat->imag))));
1521rb_complex_hash(
VALUE self)
1527 n = rb_hash(dat->real);
1529 n = rb_hash(dat->imag);
1548nucomp_hash(
VALUE self)
1550 return ST2FIX(rb_complex_hash(self));
1558 get_dat2(self, other);
1562 f_eqeq_p(self, other));
1573 return !isnan(f) && signbit(f);
1575 return f_negative_p(x);
1579f_tpositive_p(
VALUE x)
1581 return !f_signbit(x);
1591 impos = f_tpositive_p(dat->imag);
1597 if (!
rb_isdigit(RSTRING_PTR(s)[RSTRING_LEN(s) - 1]))
1618nucomp_to_s(
VALUE self)
1637nucomp_inspect(
VALUE self)
1648#define FINITE_TYPE_P(v) (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))
1663rb_complex_finite_p(
VALUE self)
1667 return RBOOL(f_finite_p(dat->real) && f_finite_p(dat->imag));
1683rb_complex_infinite_p(
VALUE self)
1687 if (!f_infinite_p(dat->real) && !f_infinite_p(dat->imag)) {
1695nucomp_dumper(
VALUE self)
1706 RCOMPLEX_SET_REAL(dat,
rb_ivar_get(a, id_i_real));
1707 RCOMPLEX_SET_IMAG(dat,
rb_ivar_get(a, id_i_imag));
1715nucomp_marshal_dump(
VALUE self)
1731 rb_raise(rb_eArgError,
"marshaled complex must have an array whose length is 2 but %ld",
RARRAY_LEN(a));
1746 return nucomp_s_canonicalize_internal(
rb_cComplex, x, y);
1765rb_dbl_complex_new(
double real,
double imag)
1783nucomp_to_i(
VALUE self)
1787 if (!k_exact_zero_p(dat->imag)) {
1788 rb_raise(
rb_eRangeError,
"can't convert %"PRIsVALUE
" into Integer",
1791 return f_to_i(dat->real);
1807nucomp_to_f(
VALUE self)
1811 if (!k_exact_zero_p(dat->imag)) {
1812 rb_raise(
rb_eRangeError,
"can't convert %"PRIsVALUE
" into Float",
1815 return f_to_f(dat->real);
1835nucomp_to_r(
VALUE self)
1842 else if (!k_exact_zero_p(dat->imag)) {
1843 VALUE imag = rb_check_convert_type_with_id(dat->imag,
T_RATIONAL,
"Rational", idTo_r);
1844 if (
NIL_P(imag) || !k_exact_zero_p(imag)) {
1845 rb_raise(
rb_eRangeError,
"can't convert %"PRIsVALUE
" into Rational",
1885nucomp_rationalize(
int argc,
VALUE *argv,
VALUE self)
1891 if (!k_exact_zero_p(dat->imag)) {
1892 rb_raise(
rb_eRangeError,
"can't convert %"PRIsVALUE
" into Rational",
1895 return rb_funcallv(dat->real, id_rationalize, argc, argv);
1905nucomp_to_c(
VALUE self)
1917numeric_to_c(
VALUE self)
1925 return (c ==
'-' || c ==
'+');
1929read_sign(
const char **s,
1945 return isdigit((
unsigned char)c);
1949read_digits(
const char **s,
int strict,
1954 if (!isdecimal(**s))
1957 while (isdecimal(**s) || **s ==
'_') {
1960 if (strict)
return 0;
1975 }
while (**s ==
'_');
1982 return (c ==
'e' || c ==
'E');
1986read_num(
const char **s,
int strict,
1990 if (!read_digits(s, strict, b))
1998 if (!read_digits(s, strict, b)) {
2004 if (islettere(**s)) {
2009 if (!read_digits(s, strict, b)) {
2018read_den(
const char **s,
int strict,
2021 if (!read_digits(s, strict, b))
2027read_rat_nos(
const char **s,
int strict,
2030 if (!read_num(s, strict, b))
2036 if (!read_den(s, strict, b)) {
2045read_rat(
const char **s,
int strict,
2049 if (!read_rat_nos(s, strict, b))
2057 return (c ==
'i' || c ==
'I' ||
2058 c ==
'j' || c ==
'J');
2065 return rb_cstr_to_rat(s, 0);
2066 if (strpbrk(s,
".eE"))
2068 return rb_cstr_to_inum(s, 10, 0);
2072read_comp(
const char **s,
int strict,
2073 VALUE *ret,
char **b)
2081 sign = read_sign(s, b);
2083 if (isimagunit(**s)) {
2085 num =
INT2FIX((sign ==
'-') ? -1 : + 1);
2090 if (!read_rat_nos(s, strict, b)) {
2099 if (isimagunit(**s)) {
2110 st = read_rat(s, strict, b);
2112 if (strlen(bb) < 1 ||
2113 !isdecimal(*(bb + strlen(bb) - 1))) {
2118 *ret = rb_complex_new_polar(num, num2);
2127 sign = read_sign(s, b);
2128 if (isimagunit(**s))
2129 num2 =
INT2FIX((sign ==
'-') ? -1 : + 1);
2131 if (!read_rat_nos(s, strict, b)) {
2138 if (!isimagunit(**s)) {
2154skip_ws(
const char **s)
2156 while (isspace((
unsigned char)**s))
2161parse_comp(
const char *s,
int strict,
VALUE *num)
2167 buf =
ALLOCV_N(
char, tmp, strlen(s) + 1);
2171 if (!read_comp(&s, strict, num, &b)) {
2187string_to_c_strict(
VALUE self,
int raise)
2197 else if (!(s = rb_str_to_cstr(self))) {
2201 if (!parse_comp(s, TRUE, &num)) {
2202 if (!raise)
return Qnil;
2203 rb_raise(rb_eArgError,
"invalid value for convert(): %+"PRIsVALUE,
2366string_to_c(
VALUE self)
2372 (void)parse_comp(rb_str_fill_terminator(self, 1), FALSE, &num);
2378to_complex(
VALUE val)
2387 if (!raise)
return Qnil;
2388 rb_cant_convert(
Qnil,
"Complex");
2392 a1 = string_to_c_strict(a1, raise);
2397 a2 = string_to_c_strict(a2, raise);
2405 if (k_exact_zero_p(dat->imag))
2414 if (k_exact_zero_p(dat->imag))
2420 if (UNDEF_P(a2) || (k_exact_zero_p(a2)))
2425 if (k_numeric_p(a1) && !f_real_p(a1))
2428 if (!k_numeric_p(a1)) {
2430 a1 = rb_protect(to_complex, a1, NULL);
2431 rb_set_errinfo(
Qnil);
2434 return to_complex(a1);
2438 if ((k_numeric_p(a1) && k_numeric_p(a2)) &&
2439 (!f_real_p(a1) || !f_real_p(a2)))
2459 return nucomp_s_new(argc, argv2, klass);
2464nucomp_s_convert(
int argc,
VALUE *argv,
VALUE klass)
2472 return nucomp_convert(klass, a1, a2, TRUE);
2482numeric_abs2(
VALUE self)
2484 return f_mul(self, self);
2494numeric_arg(
VALUE self)
2496 if (f_positive_p(self))
2508numeric_rect(
VALUE self)
2520numeric_polar(
VALUE self)
2525 abs = rb_int_abs(self);
2526 arg = numeric_arg(self);
2529 abs = rb_float_abs(self);
2530 arg = float_arg(self);
2533 abs = rb_rational_abs(self);
2534 arg = numeric_arg(self);
2550float_arg(
VALUE self)
2554 if (f_tpositive_p(self))
2818 rb_vm_register_global_object(RFLOAT_0 =
DBL2NUM(0.0));
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
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.
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 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
Old name of RB_OBJ_FREEZE.
#define CLASS_OF
Old name of rb_class_of.
#define LONG2FIX
Old name of RB_INT2FIX.
#define FIX2INT
Old name of RB_FIX2INT.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define NUM2DBL
Old name of rb_num2dbl.
#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 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.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eTypeError
TypeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
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_cObject
Object class.
VALUE rb_mMath
Math module.
VALUE rb_cInteger
Module 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.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
#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.
VALUE rb_rational_new(VALUE num, VALUE den)
Constructs a Rational, with reduction.
st_index_t rb_memhash(const void *ptr, long len)
This is a universal hash function.
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.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
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_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 StringValueCStr(v)
Identical to StringValuePtr, except it additionally checks for the contents for viability as a C stri...
#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_integer_type_p(VALUE obj)
Queries if the object is an instance of rb_cInteger.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.