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;
863 nr = m_exp_bang(
f_sub(
f_mul(dat->real, m_log_bang(r)),
864 f_mul(dat->imag, theta)));
866 f_mul(dat->imag, m_log_bang(r)));
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))
1472 VALUE m, sr, si, re, r,
i;
1557 #define id_gsub rb_intern("gsub")
1558 #define f_gsub(x,y,z) rb_funcall((x), id_gsub, 2, (y), (z))
1586 VALUE s, a, backref;
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"));