15 #define ZERO INT2FIX(0)
16 #define ONE INT2FIX(1)
17 #define TWO INT2FIX(2)
26 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
30 f_##n(VALUE x, VALUE y)\
32 return rb_funcall(x, (op), 1, y);\
39 return rb_funcall(x, id_##n, 0);\
44 f_##n(VALUE x, VALUE y)\
46 return rb_funcall(x, id_##n, 1, y);\
53 return rb_funcall(rb_mMath, id_##n, 1, x);\
58 m_##n(VALUE x, VALUE y)\
60 return rb_funcall(rb_mMath, id_##n, 2, x, y);\
63 #define PRESERVE_SIGNEDZERO
68 #ifndef PRESERVE_SIGNEDZERO
120 #ifndef PRESERVE_SIGNEDZERO
146 #ifndef PRESERVE_SIGNEDZERO
207 #define f_positive_p(x) (!f_negative_p(x))
227 #define f_nonzero_p(x) (!f_zero_p(x))
297 #define k_exact_p(x) (!k_float_p(x))
298 #define k_inexact_p(x) k_float_p(x)
300 #define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
301 #define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
303 #define get_dat1(x) \
304 struct RComplex *dat;\
305 dat = ((struct RComplex *)(x))
307 #define get_dat2(x,y) \
308 struct RComplex *adat, *bdat;\
309 adat = ((struct RComplex *)(x));\
310 bdat = ((struct RComplex *)(y))
369 #ifdef CANONICALIZATION_FOR_MATHN
374 static int canonicalization = 0;
379 canonicalization = f;
407 if (
f_zero_p(imag) && canonicalization)
411 if (f_real_p(real) && f_real_p(imag))
413 else if (f_real_p(real)) {
417 f_sub(real, dat->imag),
420 else if (f_real_p(imag)) {
425 f_add(dat->imag, imag));
431 f_sub(adat->real, bdat->imag),
432 f_add(adat->imag, bdat->real));
489 inline static VALUE \
490 m_##n##_bang(VALUE x)\
492 return rb_math_##n(x);\
496 inline static VALUE \
497 m_##n##_bang(VALUE x, VALUE y)\
499 return rb_math_##n(x, y);\
508 #define m_hypot(x,y) m_hypot_bang((x),(y))
524 return m_cos_bang(x);
528 f_mul(m_cos_bang(dat->real),
529 m_cosh_bang(dat->imag)),
531 m_sinh_bang(dat->imag)));
539 return m_sin_bang(x);
543 f_mul(m_sin_bang(dat->real),
544 m_cosh_bang(dat->imag)),
545 f_mul(m_cos_bang(dat->real),
546 m_sinh_bang(dat->imag)));
556 return m_sqrt_bang(x);
563 return f_conj(m_sqrt(f_conj(x)));
663 real = (*func)(adat->real, bdat->real);
664 imag = (*func)(adat->imag, bdat->imag);
672 (*
func)(dat->real, other), dat->imag);
716 f_mul(adat->imag, bdat->imag));
718 f_mul(adat->imag, bdat->real));
726 f_mul(dat->real, other),
727 f_mul(dat->imag, other));
746 r = (*func)(bdat->imag, bdat->real);
754 f_mul(adat->imag, r)), n),
756 f_mul(adat->real, r)), n));
761 r = (*func)(bdat->real, bdat->imag);
778 (*
func)(dat->real, other),
779 (*
func)(dat->imag, other));
784 #define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
804 #define nucomp_quo nucomp_div
856 VALUE r, theta, nr, ntheta;
864 f_mul(dat->imag, theta)));
892 f_mul(dat->imag, dat->imag)),
907 rb_warn(
"in a**b, b may be too big");
913 f_mul(theta, other));
979 return m_hypot(dat->real, dat->imag);
993 f_mul(dat->imag, dat->imag));
1011 return m_atan2_bang(dat->imag, dat->real);
1057 nucomp_true(
VALUE self)
1078 nucomp_exact_p(
VALUE self)
1086 nucomp_inexact_p(
VALUE self)
1176 #if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun__) && \
1204 s = (*func)(dat->real);
1318 return f_to_i(dat->real);
1337 return f_to_f(dat->real);
1357 return f_to_r(dat->real);
1410 #define DIGITS "(?:[0-9](?:_[0-9]|[0-9])*)"
1411 #define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
1412 #define DENOMINATOR DIGITS
1413 #define NUMBER "[-+]?" NUMERATOR "(?:\\/" DENOMINATOR ")?"
1414 #define NUMBERNOS NUMERATOR "(?:\\/" DENOMINATOR ")?"
1415 #define PATTERN0 "\\A" WS "(" NUMBER ")@(" NUMBER ")" WS
1416 #define PATTERN1 "\\A" WS "([-+])?(" NUMBER ")?[iIjJ]" WS
1417 #define PATTERN2 "\\A" WS "(" NUMBER ")(([-+])(" NUMBERNOS ")?[iIjJ])?" WS
1422 static const char comp_pat0_source[] =
PATTERN0;
1423 static const char comp_pat1_source[] =
PATTERN1;
1424 static const char comp_pat2_source[] =
PATTERN2;
1425 static const char underscores_pat_source[] =
"_+";
1427 if (comp_pat0)
return;
1429 comp_pat0 =
rb_reg_new(comp_pat0_source,
sizeof comp_pat0_source - 1, 0);
1432 comp_pat1 =
rb_reg_new(comp_pat1_source,
sizeof comp_pat1_source - 1, 0);
1435 comp_pat2 =
rb_reg_new(comp_pat2_source,
sizeof comp_pat2_source - 1, 0);
1447 underscores_pat =
rb_reg_new(underscores_pat_source,
1448 sizeof underscores_pat_source - 1, 0);
1455 #define id_match rb_intern("match")
1456 #define f_match(x,y) rb_funcall((x), id_match, 1, (y))
1458 #define id_gsub_bang rb_intern("gsub!")
1459 #define f_gsub_bang(x,y,z) rb_funcall((x), id_gsub_bang, 2, (y), (z))
1557 #define id_gsub rb_intern("gsub")
1558 #define f_gsub(x,y,z) rb_funcall((x), id_gsub, 2, (y), (z))
1591 s =
f_gsub(
self, underscores_pat, an_underscore);
1604 VALUE a1, a2, backref;
1671 (!f_real_p(a1) || !f_real_p(a2)))
1721 return f_mul(
self,
self);
1724 #define id_PI rb_intern("PI")
1833 #define rb_intern(str) rb_intern_const(str)
1835 assert(fprintf(stderr,
"assert() is now active\n"));
RUBY_EXTERN VALUE rb_cString
static VALUE m_log_bang(VALUE x)
static VALUE nucomp_expt(VALUE self, VALUE other)
#define RSTRING_LEN(string)
static long NUM2LONG(VALUE x)
static VALUE f_mul(VALUE x, VALUE y)
static VALUE nucomp_rationalize(int argc, VALUE *argv, VALUE self)
RUBY_EXTERN VALUE rb_cFloat
VALUE rb_num_coerce_bin(VALUE, VALUE, ID)
static VALUE m_cos(VALUE x)
void rb_backref_set(VALUE)
static VALUE nucomp_to_f(VALUE self)
static VALUE nucomp_denominator(VALUE self)
RUBY_EXTERN int signbit(double x)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE nilclass_to_c(VALUE self)
static VALUE nucomp_sub(VALUE self, VALUE other)
static VALUE nucomp_imag(VALUE self)
static VALUE f_to_i(VALUE x)
SSL_METHOD *(* func)(void)
static VALUE f_complex_new2(VALUE klass, VALUE x, VALUE y)
#define RFLOAT_VALUE(val)
static VALUE f_signbit(VALUE x)
static VALUE f_lt_p(VALUE x, VALUE y)
VALUE rb_complex_polar(VALUE x, VALUE y)
static VALUE k_numeric_p(VALUE x)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static VALUE nucomp_s_new(int argc, VALUE *argv, VALUE klass)
VALUE rb_str_concat(VALUE, VALUE)
st_index_t rb_memhash(const void *ptr, long len)
static VALUE nucomp_add(VALUE self, VALUE other)
static VALUE string_to_c_strict(VALUE self)
static VALUE k_bignum_p(VALUE x)
#define RSTRING_PTR(string)
static VALUE nucomp_to_s(VALUE self)
VALUE rb_backref_get(void)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static VALUE f_complex_polar(VALUE klass, VALUE x, VALUE y)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
static VALUE nucomp_abs(VALUE self)
#define RARRAY_LEN(ARRAY)
static VALUE nucomp_negate(VALUE self)
static VALUE nucomp_mul(VALUE self, VALUE other)
double rb_str_to_dbl(VALUE, int)
VALUE rb_reg_match_post(VALUE)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
RUBY_EXTERN VALUE rb_mMath
static VALUE m_sin(VALUE x)
VALUE rb_lcm(VALUE x, VALUE y)
static VALUE nucomp_arg(VALUE self)
void rb_undef_method(VALUE klass, const char *name)
static VALUE nucomp_inspect(VALUE self)
static VALUE k_float_p(VALUE x)
#define rb_complex_new1(x)
static VALUE k_complex_p(VALUE x)
const char * rb_obj_classname(VALUE)
static VALUE f_add(VALUE x, VALUE y)
static VALUE numeric_rect(VALUE self)
static VALUE nucomp_eqeq_p(VALUE self, VALUE other)
static VALUE numeric_abs2(VALUE self)
static VALUE nucomp_eql_p(VALUE self, VALUE other)
static VALUE f_complex_new_bang1(VALUE klass, VALUE x)
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
static VALUE nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
VALUE rb_str_cat2(VALUE, const char *)
static VALUE nucomp_real(VALUE self)
static VALUE f_negative_p(VALUE x)
static VALUE string_to_c(VALUE self)
static VALUE numeric_conj(VALUE self)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE nucomp_s_alloc(VALUE klass)
void rb_define_const(VALUE, const char *, VALUE)
static void make_patterns(void)
static VALUE an_underscore
#define k_exact_zero_p(x)
static VALUE float_arg(VALUE self)
#define NEWOBJ(obj, type)
static VALUE f_tpositive_p(VALUE x)
static VALUE f_sub(VALUE x, VALUE y)
void rb_gc_register_mark_object(VALUE obj)
#define RUBY_FUNC_EXPORTED
static VALUE nucomp_fdiv(VALUE self, VALUE other)
VALUE rb_const_get(VALUE, ID)
static VALUE a_dot_and_an_e
VALUE rb_reg_new(const char *, long, int)
#define rb_complex_new2(x, y)
VALUE rb_math_log(int argc, VALUE *argv)
static VALUE numeric_arg(VALUE self)
static VALUE f_addsub(VALUE self, VALUE other, VALUE(*func)(VALUE, VALUE), ID id)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
static VALUE nucomp_to_r(VALUE self)
static VALUE f_cmp(VALUE x, VALUE y)
static VALUE f_zero_p(VALUE x)
static VALUE f_to_f(VALUE x)
RUBY_EXTERN double hypot(double, double)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE f_div(VALUE x, VALUE y)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
static VALUE f_eqeq_p(VALUE x, VALUE y)
char * strchr(char *, char)
RUBY_EXTERN VALUE rb_cInteger
void rb_match_busy(VALUE)
VALUE rb_Complex(VALUE x, VALUE y)
static VALUE nucomp_s_polar(int argc, VALUE *argv, VALUE klass)
RUBY_EXTERN VALUE rb_cNumeric
VALUE rb_complex_new(VALUE x, VALUE y)
static void nucomp_real_check(VALUE num)
static VALUE numeric_to_c(VALUE self)
static VALUE nucomp_numerator(VALUE self)
VALUE rb_usascii_str_new2(const char *)
static VALUE nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE imag)
void nucomp_canonicalization(int)
static VALUE nucomp_abs2(VALUE self)
static VALUE f_kind_of_p(VALUE x, VALUE c)
static VALUE nucomp_to_i(VALUE self)
static VALUE k_fixnum_p(VALUE x)
static VALUE f_complex_new1(VALUE klass, VALUE x)
VALUE rb_complex_raw(VALUE x, VALUE y)
static VALUE k_integer_p(VALUE x)
static VALUE k_rational_p(VALUE x)
static VALUE nucomp_rect(VALUE self)
static VALUE nucomp_marshal_load(VALUE self, VALUE a)
static VALUE f_divide(VALUE self, VALUE other, VALUE(*func)(VALUE, VALUE), ID id)
static VALUE nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag)
static VALUE string_to_c_internal(VALUE self)
static VALUE numeric_imag(VALUE self)
static VALUE nucomp_hash(VALUE self)
static VALUE nucomp_conj(VALUE self)
static VALUE nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
RUBY_EXTERN VALUE rb_cRational
#define assert(condition)
static VALUE f_complex_new_bang2(VALUE klass, VALUE x, VALUE y)
return rb_funcall(q->proc, ID_call, 0)
#define StringValuePtr(v)
static VALUE nucomp_coerce(VALUE self, VALUE other)
static VALUE numeric_polar(VALUE self)
void rb_copy_generic_ivar(VALUE, VALUE)
static VALUE nucomp_marshal_dump(VALUE self)
static VALUE f_reciprocal(VALUE x)
static VALUE f_gt_p(VALUE x, VALUE y)
static VALUE underscores_pat
RUBY_EXTERN VALUE rb_cFixnum
#define OBJSETUP(obj, c, t)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_warn(const char *fmt,...)
RUBY_EXTERN VALUE rb_cNilClass
static VALUE nucomp_false(VALUE self)
static VALUE numeric_real(VALUE self)
static VALUE nucomp_div(VALUE self, VALUE other)
static VALUE nucomp_polar(VALUE self)
VALUE rb_reg_nth_match(int, VALUE)
static VALUE f_one_p(VALUE x)
static VALUE f_format(VALUE self, VALUE(*func)(VALUE))