15 #define ZERO INT2FIX(0)
16 #define ONE INT2FIX(1)
17 #define TWO INT2FIX(2)
27 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
31 f_##n(VALUE x, VALUE y)\
33 return rb_funcall(x, (op), 1, y);\
40 return rb_funcall(x, id_##n, 0);\
45 f_##n(VALUE x, VALUE y)\
47 return rb_funcall(x, id_##n, 1, y);\
54 return rb_funcall(rb_mMath, id_##n, 1, x);\
59 m_##n(VALUE x, VALUE y)\
61 return rb_funcall(rb_mMath, id_##n, 2, x, y);\
64 #define PRESERVE_SIGNEDZERO
69 #ifndef PRESERVE_SIGNEDZERO
121 #ifndef PRESERVE_SIGNEDZERO
147 #ifndef PRESERVE_SIGNEDZERO
208 #define f_positive_p(x) (!f_negative_p(x))
228 #define f_nonzero_p(x) (!f_zero_p(x))
298 #define k_exact_p(x) (!k_float_p(x))
299 #define k_inexact_p(x) k_float_p(x)
301 #define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
302 #define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
304 #define get_dat1(x) \
305 struct RComplex *dat;\
306 dat = ((struct RComplex *)(x))
308 #define get_dat2(x,y) \
309 struct RComplex *adat, *bdat;\
310 adat = ((struct RComplex *)(x));\
311 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));
516 inline static VALUE \
517 m_##n##_bang(VALUE x)\
519 return rb_math_##n(x);\
523 inline static VALUE \
524 m_##n##_bang(VALUE x, VALUE y)\
526 return rb_math_##n(x, y);\
535 #define m_hypot(x,y) m_hypot_bang((x),(y))
551 return m_cos_bang(x);
555 f_mul(m_cos_bang(dat->real),
556 m_cosh_bang(dat->imag)),
558 m_sinh_bang(dat->imag)));
566 return m_sin_bang(x);
570 f_mul(m_sin_bang(dat->real),
571 m_cosh_bang(dat->imag)),
572 f_mul(m_cos_bang(dat->real),
573 m_sinh_bang(dat->imag)));
583 return m_sqrt_bang(x);
590 return f_conj(m_sqrt(f_conj(x)));
698 real = (*func)(adat->real, bdat->real);
699 imag = (*func)(adat->imag, bdat->imag);
707 (*
func)(dat->real, other), dat->imag);
769 f_mul(adat->imag, bdat->imag));
771 f_mul(adat->imag, bdat->real));
779 f_mul(dat->real, other),
780 f_mul(dat->imag, other));
799 r = (*func)(bdat->imag, bdat->real);
807 f_mul(adat->imag, r)), n),
809 f_mul(adat->real, r)), n));
814 r = (*func)(bdat->real, bdat->imag);
831 (*
func)(dat->real, other),
832 (*
func)(dat->imag, other));
837 #define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
858 #define nucomp_quo nucomp_div
906 VALUE r, theta, nr, ntheta;
914 f_mul(dat->imag, theta)));
942 f_mul(dat->imag, dat->imag)),
957 rb_warn(
"in a**b, b may be too big");
963 f_mul(theta, other));
1038 return m_hypot(dat->real, dat->imag);
1055 f_mul(dat->imag, dat->imag));
1072 return m_atan2_bang(dat->imag, dat->real);
1124 nucomp_true(
VALUE self)
1145 nucomp_exact_p(
VALUE self)
1153 nucomp_inexact_p(
VALUE self)
1241 #if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
1269 s = (*func)(dat->real);
1417 return f_to_i(dat->real);
1441 return f_to_f(dat->real);
1467 return f_to_r(dat->real);
1542 return (c ==
'-' || c ==
'+');
1562 return isdigit((
unsigned char)c);
1592 }
while (**s ==
'_');
1599 return (c ==
'e' || c ==
'E');
1674 return (c ==
'i' || c ==
'I' ||
1675 c ==
'j' || c ==
'J');
1685 if (strpbrk(s,
".eE"))
1704 num =
INT2FIX((sign ==
'-') ? -1 : + 1);
1748 num2 =
INT2FIX((sign ==
'-') ? -1 : + 1);
1775 while (isspace((
unsigned char)**s))
1887 VALUE a1, a2, backref;
1954 (!f_real_p(a1) || !f_real_p(a2)))
2004 return f_mul(
self,
self);
2007 #define id_PI rb_intern("PI")
2117 #define rb_intern(str) rb_intern_const(str)
2119 assert(fprintf(stderr,
"assert() is now active\n"));
static int read_rat_nos(const char **s, int strict, char **b)
static VALUE m_log_bang(VALUE x)
static VALUE nucomp_expt(VALUE self, VALUE other)
#define RB_TYPE_P(obj, type)
static int islettere(int c)
static VALUE f_mul(VALUE x, VALUE y)
static VALUE nucomp_rationalize(int argc, VALUE *argv, VALUE self)
void rb_match_busy(VALUE)
RUBY_EXTERN VALUE rb_cNilClass
static VALUE m_cos(VALUE x)
size_t strlen(const char *)
const char * rb_obj_classname(VALUE)
static VALUE nucomp_to_f(VALUE self)
static VALUE nucomp_denominator(VALUE self)
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)
#define rb_complex_new1(x)
static VALUE nucomp_sub(VALUE self, VALUE other)
static VALUE nucomp_imag(VALUE self)
static VALUE f_to_i(VALUE x)
double rb_cstr_to_dbl(const char *, int)
SSL_METHOD *(* func)(void)
#define rb_usascii_str_new2
VALUE rb_const_get(VALUE, ID)
static VALUE f_complex_new2(VALUE klass, VALUE x, VALUE y)
static VALUE f_signbit(VALUE x)
RUBY_EXTERN int signbit(double x)
static VALUE f_lt_p(VALUE x, VALUE y)
VALUE rb_complex_polar(VALUE x, VALUE y)
static int isimagunit(int c)
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)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static int read_rat(const char **s, int strict, char **b)
static VALUE nucomp_add(VALUE self, VALUE other)
static VALUE string_to_c_strict(VALUE self)
static VALUE k_bignum_p(VALUE x)
RUBY_EXTERN VALUE rb_cFloat
static VALUE nucomp_to_s(VALUE self)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE f_complex_polar(VALUE klass, VALUE x, VALUE y)
static VALUE nucomp_abs(VALUE self)
static VALUE nucomp_negate(VALUE self)
static VALUE nucomp_mul(VALUE self, VALUE other)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
void rb_must_asciicompat(VALUE)
static VALUE m_sin(VALUE x)
static VALUE nucomp_to_c(VALUE self)
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)
VALUE rb_ivar_get(VALUE, ID)
static VALUE k_float_p(VALUE x)
VALUE rb_str_concat(VALUE, VALUE)
static VALUE k_complex_p(VALUE x)
static VALUE f_add(VALUE x, VALUE y)
static VALUE str2num(char *s)
void rb_copy_generic_ivar(VALUE, VALUE)
static VALUE numeric_rect(VALUE self)
VALUE rb_cstr_to_rat(const char *, int)
RUBY_EXTERN VALUE rb_mMath
static VALUE nucomp_eqeq_p(VALUE self, VALUE other)
static VALUE numeric_abs2(VALUE self)
static VALUE nucomp_eql_p(VALUE self, VALUE other)
#define StringValuePtr(v)
static VALUE f_complex_new_bang1(VALUE klass, VALUE x)
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
RUBY_EXTERN VALUE rb_cRational
static VALUE nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
static int parse_comp(const char *s, int strict, VALUE *num)
static VALUE nucomp_real(VALUE self)
static VALUE f_negative_p(VALUE x)
void rb_define_const(VALUE, const char *, VALUE)
static VALUE string_to_c(VALUE self)
VALUE rb_str_cat2(VALUE, const char *)
static VALUE numeric_conj(VALUE self)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
RUBY_EXTERN double hypot(double, double)
static VALUE nucomp_s_alloc(VALUE klass)
void rb_backref_set(VALUE)
#define k_exact_zero_p(x)
static VALUE float_arg(VALUE self)
static VALUE f_tpositive_p(VALUE x)
static int read_den(const char **s, int strict, char **b)
double rb_str_to_dbl(VALUE, int)
static VALUE f_sub(VALUE x, VALUE y)
#define RUBY_FUNC_EXPORTED
unsigned char buf[MIME_BUF_SIZE]
static int read_comp(const char **s, int strict, VALUE *ret, char **b)
static VALUE nucomp_fdiv(VALUE self, VALUE other)
RUBY_EXTERN VALUE rb_cInteger
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)
static VALUE nucomp_to_r(VALUE self)
RUBY_EXTERN VALUE rb_cFixnum
static VALUE f_cmp(VALUE x, VALUE y)
static VALUE f_zero_p(VALUE x)
static VALUE f_to_f(VALUE x)
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)
VALUE rb_Complex(VALUE x, VALUE y)
static VALUE nucomp_s_polar(int argc, VALUE *argv, VALUE klass)
VALUE rb_complex_new(VALUE x, VALUE y)
RUBY_EXTERN VALUE rb_cString
static void nucomp_real_check(VALUE num)
static VALUE numeric_to_c(VALUE self)
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
static void skip_ws(const char **s)
static VALUE nucomp_numerator(VALUE self)
VALUE rb_ivar_set(VALUE, ID, VALUE)
void rb_str_modify(VALUE)
#define NEWOBJ_OF(obj, type, klass, flags)
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)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
static VALUE k_fixnum_p(VALUE x)
st_index_t rb_memhash(const void *ptr, long len)
static VALUE f_complex_new1(VALUE klass, VALUE x)
VALUE rb_complex_raw(VALUE x, VALUE y)
static VALUE k_integer_p(VALUE x)
RUBY_EXTERN VALUE rb_cObject
static VALUE nucomp_dumper(VALUE self)
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 int read_sign(const char **s, char **b)
VALUE rb_backref_get(void)
static VALUE numeric_imag(VALUE self)
static VALUE nucomp_loader(VALUE self, VALUE a)
static VALUE nucomp_hash(VALUE self)
static VALUE nucomp_conj(VALUE self)
static VALUE nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
#define assert(condition)
static VALUE f_complex_new_bang2(VALUE klass, VALUE x, VALUE y)
static VALUE nucomp_coerce(VALUE self, VALUE other)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
#define rb_complex_new2(x, y)
static int read_digits(const char **s, int strict, char **b)
static VALUE numeric_polar(VALUE self)
static VALUE nucomp_marshal_dump(VALUE self)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
static VALUE f_reciprocal(VALUE x)
static VALUE f_gt_p(VALUE x, VALUE y)
VALUE rb_num_coerce_bin(VALUE, VALUE, ID)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define ALLOCV_N(type, v, n)
void rb_warn(const char *fmt,...)
static int isdecimal(int c)
static VALUE nucomp_false(VALUE self)
static VALUE numeric_real(VALUE self)
RUBY_EXTERN VALUE rb_cNumeric
static VALUE nucomp_div(VALUE self, VALUE other)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static VALUE nucomp_polar(VALUE self)
static VALUE f_one_p(VALUE x)
static VALUE f_format(VALUE self, VALUE(*func)(VALUE))
static int read_num(const char **s, int strict, char **b)