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
70f_add(VALUE x, VALUE y)
78 return rb_int_plus(x, y);
84 return rb_float_plus(x, y);
90 return rb_rational_plus(x, y);
97f_div(VALUE x, VALUE y)
105f_gt_p(VALUE x, VALUE 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);
122f_mul(VALUE x, VALUE y)
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);
136 if (y == ONE)
return x;
137 return rb_float_mul(x, y);
141 if (y == ONE)
return x;
142 return rb_rational_mul(x, y);
145 if (y == ONE)
return x;
151f_sub(VALUE x, VALUE y)
153 if (FIXNUM_ZERO_P(y) &&
164 return rb_int_abs(x);
167 return rb_float_abs(x);
170 return rb_rational_abs(x);
178static VALUE numeric_arg(VALUE
self);
179static VALUE float_arg(VALUE
self);
185 return numeric_arg(x);
191 return numeric_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);
241static bool nucomp_real_p(VALUE
self);
256 return nucomp_real_p(x);
273 return DBL2NUM(rb_str_to_dbl(x, 0));
280f_eqeq_p(VALUE x, VALUE y)
286 return (
int)rb_equal(x, y);
293f_quo(VALUE x, VALUE y)
296 return rb_numeric_quo(x, y);
298 return rb_float_div(x, y);
300 return rb_numeric_quo(x, 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);
332 return (
int)rb_equal(x, ZERO);
335#define f_nonzero_p(x) (!f_zero_p(x))
338always_finite_type_p(VALUE x)
348 if (always_finite_type_p(x)) {
360 if (always_finite_type_p(x)) {
370f_kind_of_p(VALUE x, VALUE c)
372 return (
int)rb_obj_is_kind_of(x, c);
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)
392nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag)
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);
410f_complex_new_bang1(VALUE klass, VALUE x)
413 return nucomp_s_new_internal(klass, x, ZERO);
417f_complex_new_bang2(VALUE klass, VALUE x, VALUE y)
421 return nucomp_s_new_internal(klass, x, y);
425nucomp_real_check(VALUE num)
430 if (!k_numeric_p(num) || !f_real_p(num))
431 rb_raise(rb_eTypeError,
"not a real");
436nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE imag)
438 int complex_r, complex_i;
441 if (!complex_r && !complex_i) {
442 return nucomp_s_new_internal(klass, real, imag);
444 else if (!complex_r) {
447 return nucomp_s_new_internal(klass,
448 f_sub(real, dat->imag),
449 f_add(ZERO, dat->real));
451 else if (!complex_i) {
454 return nucomp_s_new_internal(klass,
456 f_add(dat->imag, imag));
459 get_dat2(real, imag);
461 return nucomp_s_new_internal(klass,
462 f_sub(adat->real, bdat->imag),
463 f_add(adat->imag, bdat->real));
477nucomp_s_new(
int argc, VALUE *argv, VALUE klass)
483 nucomp_real_check(real);
487 nucomp_real_check(real);
488 nucomp_real_check(imag);
492 return nucomp_s_canonicalize_internal(klass, real, imag);
496f_complex_new2(VALUE klass, VALUE x, VALUE y)
499 return nucomp_s_canonicalize_internal(klass, x, y);
502static VALUE nucomp_convert(VALUE klass, VALUE a1, VALUE a2,
int raise);
503static VALUE nucomp_s_convert(
int argc, VALUE *argv, VALUE klass);
542nucomp_f_complex(
int argc, VALUE *argv, VALUE klass)
544 VALUE a1, a2, opts =
Qnil;
547 if (
rb_scan_args(argc, argv,
"11:", &a1, &a2, &opts) == 1) {
551 raise = rb_opts_exception_p(opts,
raise);
561m_##n##_bang(VALUE x)\
563 return rb_math_##n(x);\
573 return rb_math_log(1, &x);
583 return m_cos_bang(x);
587 f_mul(m_cos_bang(dat->real),
588 m_cosh_bang(dat->imag)),
589 f_mul(f_negate(m_sin_bang(dat->real)),
590 m_sinh_bang(dat->imag)));
598 return m_sin_bang(x);
602 f_mul(m_sin_bang(dat->real),
603 m_cosh_bang(dat->imag)),
604 f_mul(m_cos_bang(dat->real),
605 m_sinh_bang(dat->imag)));
610f_complex_polar(VALUE klass, VALUE x, VALUE y)
614 if (f_zero_p(x) || f_zero_p(y)) {
615 return nucomp_s_new_internal(klass, x, RFLOAT_0);
623 else if (arg == M_PI_2) {
627 else if (arg == M_PI_2+M_PI) {
633 const double real = abs * cos(arg), imag = abs * sin(arg);
638 const double ax = sin(arg), ay = cos(arg);
642 return nucomp_s_new_internal(klass, x, y);
644 return nucomp_s_canonicalize_internal(klass,
650# define cospi(x) __cospi(x)
652# define cospi(x) cos((x) * M_PI)
655# define sinpi(x) __sinpi(x)
657# define sinpi(x) sin((x) * M_PI)
661rb_dbl_complex_new_polar_pi(
double abs,
double ang)
664 const double fr = modf(ang, &fi);
665 int pos = fr == +0.5;
667 if (pos || fr == -0.5) {
668 if ((modf(fi / 2.0, &fi) != fr) ^ pos) abs = -abs;
671 else if (fr == 0.0) {
672 if (modf(fi / 2.0, &fi) != 0.0) abs = -abs;
676 const double real = abs * cospi(ang), imag = abs * sinpi(ang);
693nucomp_s_polar(
int argc, VALUE *argv, VALUE klass)
698 nucomp_real_check(abs);
700 nucomp_real_check(arg);
713 return f_complex_polar(klass, abs, arg);
761 return f_complex_new2(
CLASS_OF(
self),
762 f_negate(dat->real), f_negate(dat->imag));
783 get_dat2(
self, other);
785 real = f_add(adat->real, bdat->real);
786 imag = f_add(adat->imag, bdat->imag);
788 return f_complex_new2(
CLASS_OF(
self), real, imag);
790 if (k_numeric_p(other) && f_real_p(other)) {
793 return f_complex_new2(
CLASS_OF(
self),
794 f_add(dat->real, other), dat->imag);
817 get_dat2(
self, other);
819 real = f_sub(adat->real, bdat->real);
820 imag = f_sub(adat->imag, bdat->imag);
822 return f_complex_new2(
CLASS_OF(
self), real, imag);
824 if (k_numeric_p(other) && f_real_p(other)) {
827 return f_complex_new2(
CLASS_OF(
self),
828 f_sub(dat->real, other), dat->imag);
834safe_mul(VALUE a, VALUE b,
int az,
int bz)
847comp_mul(VALUE areal, VALUE aimag, VALUE breal, VALUE bimag, VALUE *real, VALUE *imag)
849 int arzero = f_zero_p(areal);
850 int aizero = f_zero_p(aimag);
851 int brzero = f_zero_p(breal);
852 int bizero = f_zero_p(bimag);
853 *real = f_sub(safe_mul(areal, breal, arzero, brzero),
854 safe_mul(aimag, bimag, aizero, bizero));
855 *imag = f_add(safe_mul(areal, bimag, arzero, bizero),
856 safe_mul(aimag, breal, aizero, brzero));
876 get_dat2(
self, other);
878 comp_mul(adat->real, adat->imag, bdat->real, bdat->imag, &real, &imag);
880 return f_complex_new2(
CLASS_OF(
self), real, imag);
882 if (k_numeric_p(other) && f_real_p(other)) {
885 return f_complex_new2(
CLASS_OF(
self),
886 f_mul(dat->real, other),
887 f_mul(dat->imag, other));
893f_divide(VALUE
self, VALUE other,
894 VALUE (*func)(VALUE, VALUE), ID
id)
899 get_dat2(
self, other);
904 if (f_gt_p(f_abs(bdat->real), f_abs(bdat->imag))) {
905 r = (*func)(bdat->imag, bdat->real);
906 n = f_mul(bdat->real, f_add(ONE, f_mul(r, r)));
907 x = (*func)(f_add(adat->real, f_mul(adat->imag, r)), n);
908 y = (*func)(f_sub(adat->imag, f_mul(adat->real, r)), n);
911 r = (*func)(bdat->real, bdat->imag);
912 n = f_mul(bdat->imag, f_add(ONE, f_mul(r, r)));
913 x = (*func)(f_add(f_mul(adat->real, r), adat->imag), n);
914 y = (*func)(f_sub(f_mul(adat->imag, r), adat->real), n);
917 x = rb_rational_canonicalize(x);
918 y = rb_rational_canonicalize(y);
920 return f_complex_new2(
CLASS_OF(
self), x, y);
922 if (k_numeric_p(other) && f_real_p(other)) {
925 x = rb_rational_canonicalize((*func)(dat->real, other));
926 y = rb_rational_canonicalize((*func)(dat->imag, other));
927 return f_complex_new2(
CLASS_OF(
self), x, y);
932#define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
950 return f_divide(
self, other, f_quo, id_quo);
953#define nucomp_quo rb_complex_div
964nucomp_fdiv(VALUE
self, VALUE other)
966 return f_divide(
self, other, f_fdiv, id_fdiv);
972 return f_quo(ONE, x);
987 if (k_numeric_p(other) && k_exact_zero_p(other))
988 return f_complex_new_bang1(
CLASS_OF(
self), ONE);
991 other = RRATIONAL(other)->num;
996 if (k_exact_zero_p(dat->imag))
1001 VALUE r, theta, nr, ntheta;
1006 theta = f_arg(
self);
1008 nr = m_exp_bang(f_sub(f_mul(dat->real, m_log_bang(r)),
1009 f_mul(dat->imag, theta)));
1010 ntheta = f_add(f_mul(theta, dat->real),
1011 f_mul(dat->imag, m_log_bang(r)));
1012 return f_complex_polar(
CLASS_OF(
self), nr, ntheta);
1017 return nucomp_s_new_internal(
CLASS_OF(
self), ONE, ZERO);
1020 self = f_reciprocal(
self);
1021 other = rb_int_uminus(other);
1026 VALUE xr = dat->real, xi = dat->imag, zr = xr, zi = xi;
1029 zr = rb_num_pow(zr, other);
1031 else if (f_zero_p(xr)) {
1032 zi = rb_num_pow(zi, other);
1033 if (n & 2) zi = f_negate(zi);
1044 for (; q = n / 2, r = n % 2, r == 0; n = q) {
1045 VALUE tmp = f_sub(f_mul(xr, xr), f_mul(xi, xi));
1046 xi = f_mul(f_mul(TWO, xr), xi);
1049 comp_mul(zr, zi, xr, xi, &zr, &zi);
1052 return nucomp_s_new_internal(
CLASS_OF(
self), zr, zi);
1055 if (k_numeric_p(other) && f_real_p(other)) {
1058 if (RB_BIGNUM_TYPE_P(other))
1059 rb_warn(
"in a**b, b may be too big");
1062 theta = f_arg(
self);
1064 return f_complex_polar(
CLASS_OF(
self), f_expt(r, other),
1065 f_mul(theta, other));
1083nucomp_eqeq_p(VALUE
self, VALUE other)
1086 get_dat2(
self, other);
1088 return RBOOL(f_eqeq_p(adat->real, bdat->real) &&
1089 f_eqeq_p(adat->imag, bdat->imag));
1091 if (k_numeric_p(other) && f_real_p(other)) {
1094 return RBOOL(f_eqeq_p(dat->real, other) && f_zero_p(dat->imag));
1096 return RBOOL(f_eqeq_p(other,
self));
1100nucomp_real_p(VALUE
self)
1103 return(f_zero_p(dat->imag) ?
true :
false);
1121nucomp_cmp(VALUE
self, VALUE other)
1123 if (nucomp_real_p(
self) && k_numeric_p(other)) {
1125 get_dat2(
self, other);
1126 return rb_funcall(adat->real, idCmp, 1, bdat->real);
1128 else if (f_real_p(other)) {
1130 return rb_funcall(dat->real, idCmp, 1, other);
1138nucomp_coerce(VALUE
self, VALUE other)
1142 if (k_numeric_p(other) && f_real_p(other))
1145 rb_raise(rb_eTypeError,
"%"PRIsVALUE
" can't be coerced into %"PRIsVALUE,
1146 rb_obj_class(other), rb_obj_class(
self));
1165 if (f_zero_p(dat->real)) {
1166 VALUE a = f_abs(dat->imag);
1171 if (f_zero_p(dat->imag)) {
1172 VALUE a = f_abs(dat->real);
1177 return rb_math_hypot(dat->real, dat->imag);
1190nucomp_abs2(VALUE
self)
1193 return f_add(f_mul(dat->real, dat->real),
1194 f_mul(dat->imag, dat->imag));
1211 return rb_math_atan2(dat->imag, dat->real);
1224nucomp_rect(VALUE
self)
1239nucomp_polar(VALUE
self)
1257 return f_complex_new2(
CLASS_OF(
self), dat->real, f_negate(dat->imag));
1268nucomp_real_p_m(VALUE
self)
1282nucomp_denominator(VALUE
self)
1285 return rb_lcm(f_denominator(dat->real), f_denominator(dat->imag));
1307nucomp_numerator(VALUE
self)
1313 cd = nucomp_denominator(
self);
1314 return f_complex_new2(
CLASS_OF(
self),
1315 f_mul(f_numerator(dat->real),
1316 f_div(cd, f_denominator(dat->real))),
1317 f_mul(f_numerator(dat->imag),
1318 f_div(cd, f_denominator(dat->imag))));
1323rb_complex_hash(VALUE
self)
1338nucomp_hash(VALUE
self)
1340 return ST2FIX(rb_complex_hash(
self));
1345nucomp_eql_p(VALUE
self, VALUE other)
1348 get_dat2(
self, other);
1352 f_eqeq_p(
self, other));
1363 return !isnan(f) && signbit(f);
1365 return f_negative_p(x);
1369f_tpositive_p(VALUE x)
1371 return !f_signbit(x);
1375f_format(VALUE
self, VALUE (*func)(VALUE))
1382 impos = f_tpositive_p(dat->imag);
1384 s = (*func)(dat->real);
1408nucomp_to_s(VALUE
self)
1410 return f_format(
self, rb_String);
1426nucomp_inspect(VALUE
self)
1437#define FINITE_TYPE_P(v) (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))
1447rb_complex_finite_p(VALUE
self)
1451 return RBOOL(f_finite_p(dat->real) && f_finite_p(dat->imag));
1467rb_complex_infinite_p(VALUE
self)
1471 if (!f_infinite_p(dat->real) && !f_infinite_p(dat->imag)) {
1479nucomp_dumper(VALUE
self)
1486nucomp_loader(VALUE
self, VALUE a)
1490 RCOMPLEX_SET_REAL(dat,
rb_ivar_get(a, id_i_real));
1491 RCOMPLEX_SET_IMAG(dat,
rb_ivar_get(a, id_i_imag));
1499nucomp_marshal_dump(VALUE
self)
1511nucomp_marshal_load(VALUE
self, VALUE a)
1515 rb_raise(rb_eArgError,
"marshaled complex must have an array whose length is 2 but %ld",
RARRAY_LEN(a));
1530 return nucomp_s_canonicalize_internal(
rb_cComplex, x, y);
1572nucomp_to_i(VALUE
self)
1576 if (!k_exact_zero_p(dat->imag)) {
1577 rb_raise(rb_eRangeError,
"can't convert %"PRIsVALUE
" into Integer",
1580 return f_to_i(dat->real);
1595nucomp_to_f(VALUE
self)
1599 if (!k_exact_zero_p(dat->imag)) {
1600 rb_raise(rb_eRangeError,
"can't convert %"PRIsVALUE
" into Float",
1603 return f_to_f(dat->real);
1620nucomp_to_r(VALUE
self)
1624 if (!k_exact_zero_p(dat->imag)) {
1625 rb_raise(rb_eRangeError,
"can't convert %"PRIsVALUE
" into Rational",
1628 return f_to_r(dat->real);
1645nucomp_rationalize(
int argc, VALUE *argv, VALUE
self)
1651 if (!k_exact_zero_p(dat->imag)) {
1652 rb_raise(rb_eRangeError,
"can't convert %"PRIsVALUE
" into Rational",
1655 return rb_funcallv(dat->real, id_rationalize, argc, argv);
1668nucomp_to_c(VALUE
self)
1680nilclass_to_c(VALUE
self)
1692numeric_to_c(VALUE
self)
1700 return (c ==
'-' || c ==
'+');
1704read_sign(
const char **s,
1720 return isdigit((
unsigned char)c);
1724read_digits(
const char **s,
int strict,
1729 if (!isdecimal(**s))
1732 while (isdecimal(**s) || **s ==
'_') {
1750 }
while (**s ==
'_');
1757 return (c ==
'e' || c ==
'E');
1761read_num(
const char **s,
int strict,
1765 if (!read_digits(s, strict, b))
1773 if (!read_digits(s, strict, b)) {
1779 if (islettere(**s)) {
1784 if (!read_digits(s, strict, b)) {
1793read_den(
const char **s,
int strict,
1796 if (!read_digits(s, strict, b))
1802read_rat_nos(
const char **s,
int strict,
1805 if (!read_num(s, strict, b))
1811 if (!read_den(s, strict, b)) {
1820read_rat(
const char **s,
int strict,
1824 if (!read_rat_nos(s, strict, b))
1832 return (c ==
'i' || c ==
'I' ||
1833 c ==
'j' || c ==
'J');
1840 return rb_cstr_to_rat(s, 0);
1841 if (strpbrk(s,
".eE"))
1847read_comp(
const char **s,
int strict,
1848 VALUE *ret,
char **b)
1856 sign = read_sign(s, b);
1858 if (isimagunit(**s)) {
1860 num =
INT2FIX((sign ==
'-') ? -1 : + 1);
1865 if (!read_rat_nos(s, strict, b)) {
1874 if (isimagunit(**s)) {
1885 st = read_rat(s, strict, b);
1887 if (strlen(bb) < 1 ||
1888 !isdecimal(*(bb + strlen(bb) - 1))) {
1902 sign = read_sign(s, b);
1903 if (isimagunit(**s))
1904 num2 =
INT2FIX((sign ==
'-') ? -1 : + 1);
1906 if (!read_rat_nos(s, strict, b)) {
1913 if (!isimagunit(**s)) {
1929skip_ws(
const char **s)
1931 while (isspace((
unsigned char)**s))
1936parse_comp(
const char *s,
int strict, VALUE *num)
1942 buf =
ALLOCV_N(
char, tmp, strlen(s) + 1);
1946 if (!read_comp(&s, strict, num, &b)) {
1962string_to_c_strict(VALUE
self,
int raise)
1972 if (!
raise)
return Qnil;
1973 rb_raise(rb_eArgError,
"string contains null byte");
1985 if (!parse_comp(s, 1, &num)) {
1986 if (!
raise)
return Qnil;
1987 rb_raise(rb_eArgError,
"invalid value for convert(): %+"PRIsVALUE,
2018string_to_c(VALUE
self)
2036 (void)parse_comp(s, 0, &num);
2042to_complex(VALUE val)
2048nucomp_convert(VALUE klass, VALUE a1, VALUE a2,
int raise)
2051 if (!
raise)
return Qnil;
2052 rb_raise(rb_eTypeError,
"can't convert nil into Complex");
2056 a1 = string_to_c_strict(a1,
raise);
2061 a2 = string_to_c_strict(a2,
raise);
2069 if (k_exact_zero_p(dat->imag))
2078 if (k_exact_zero_p(dat->imag))
2084 if (a2 ==
Qundef || (k_exact_zero_p(a2)))
2089 if (k_numeric_p(a1) && !f_real_p(a1))
2092 if (!k_numeric_p(a1)) {
2095 return to_complex(a1);
2099 if ((k_numeric_p(a1) && k_numeric_p(a2)) &&
2100 (!f_real_p(a1) || !f_real_p(a2)))
2120 return nucomp_s_new(argc, argv2, klass);
2125nucomp_s_convert(
int argc, VALUE *argv, VALUE klass)
2133 return nucomp_convert(klass, a1, a2, TRUE);
2143numeric_real(VALUE
self)
2156numeric_imag(VALUE
self)
2168numeric_abs2(VALUE
self)
2170 return f_mul(
self,
self);
2182numeric_arg(VALUE
self)
2184 if (f_positive_p(
self))
2197numeric_rect(VALUE
self)
2209numeric_polar(VALUE
self)
2214 abs = rb_int_abs(
self);
2215 arg = numeric_arg(
self);
2218 abs = rb_float_abs(
self);
2219 arg = float_arg(
self);
2222 abs = rb_rational_abs(
self);
2223 arg = numeric_arg(
self);
2240numeric_conj(VALUE
self)
2254float_arg(VALUE
self)
2258 if (f_tpositive_p(
self))
static int rb_isdigit(int c)
Our own locale-insensitive version of isdigit(3).
#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.
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.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#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 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.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
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_cNumeric
Numeric 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_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.
void rb_gc_register_mark_object(VALUE object)
Inform the garbage collector that object is a live Ruby object that should not be moved.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
Identical to rb_cstr2inum(), except it takes Ruby's strings instead of C's.
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
Parses C's string to convert into a Ruby's integer.
int rb_cmpint(VALUE val, VALUE a, VALUE b)
Canonicalises the passed val, which is the return value of a <=> b, into C's {-1, 0,...
VALUE rb_complex_uminus(VALUE z)
Performs negation of the passed object.
VALUE rb_complex_div(VALUE x, VALUE y)
Performs division of the passed two objects.
VALUE rb_complex_new(VALUE real, VALUE imag)
Constructs a Complex, by first multiplying the imaginary part with 1i then adds it to the real part.
VALUE rb_complex_plus(VALUE x, VALUE y)
Performs addition of the passed two objects.
VALUE rb_complex_new_polar(VALUE abs, VALUE arg)
Constructs a Complex using polar representations.
VALUE rb_complex_arg(VALUE z)
Queries the argument (or the angle) of the passed object.
#define rb_complex_new2(x, y)
Just another name of rb_complex_new.
VALUE rb_complex_raw(VALUE real, VALUE imag)
Identical to rb_complex_new(), except it assumes both arguments are not instances of rb_cComplex.
VALUE rb_dbl_complex_new(double real, double imag)
Identical to rb_complex_new(), except it takes the arguments as C's double instead of Ruby's object.
VALUE rb_complex_abs(VALUE z)
Queries the absolute (or the magnitude) of the passed object.
VALUE rb_complex_real(VALUE z)
Queries the real part of the passed Complex.
VALUE rb_complex_mul(VALUE x, VALUE y)
Performs multiplication of the passed two objects.
VALUE rb_complex_conjugate(VALUE z)
Performs complex conjugation of the passed object.
VALUE rb_Complex(VALUE real, VALUE imag)
Converts various values into a Complex.
VALUE rb_complex_minus(VALUE x, VALUE y)
Performs subtraction of the passed two objects.
#define rb_complex_new1(x)
Shorthand of x+0i.
VALUE rb_complex_pow(VALUE base, VALUE exp)
Performs exponentiation of the passed two objects.
VALUE rb_complex_imag(VALUE z)
Queries the imaginary part of the passed Complex.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
VALUE rb_hash(VALUE obj)
Calculates a message authentication code of the passed object.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
VALUE rb_num_coerce_bin(VALUE lhs, VALUE rhs, ID op)
Coerced binary operation.
VALUE rb_protect(VALUE(*func)(VALUE args), VALUE args, int *state)
Protects a function call from potential global escapes from the function.
st_index_t rb_memhash(const void *ptr, long len)
This is a universal hash function.
VALUE rb_str_cat2(VALUE, const char *)
Just another name of rb_str_cat_cstr.
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.
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_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.
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.