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));
518 inline static VALUE \
519 m_##n##_bang(VALUE x)\
521 return rb_math_##n(x);\
525 inline static VALUE \
526 m_##n##_bang(VALUE x, VALUE y)\
528 return rb_math_##n(x, y);\
537 #define m_hypot(x,y) m_hypot_bang((x),(y))
553 return m_cos_bang(x);
557 f_mul(m_cos_bang(dat->real),
558 m_cosh_bang(dat->imag)),
560 m_sinh_bang(dat->imag)));
568 return m_sin_bang(x);
572 f_mul(m_sin_bang(dat->real),
573 m_cosh_bang(dat->imag)),
574 f_mul(m_cos_bang(dat->real),
575 m_sinh_bang(dat->imag)));
585 return m_sqrt_bang(x);
592 return f_conj(m_sqrt(f_conj(x)));
700 real = (*func)(adat->real, bdat->real);
701 imag = (*func)(adat->imag, bdat->imag);
709 (*
func)(dat->real, other), dat->imag);
771 f_mul(adat->imag, bdat->imag));
773 f_mul(adat->imag, bdat->real));
781 f_mul(dat->real, other),
782 f_mul(dat->imag, other));
801 r = (*func)(bdat->imag, bdat->real);
809 f_mul(adat->imag, r)), n),
811 f_mul(adat->real, r)), n));
816 r = (*func)(bdat->real, bdat->imag);
833 (*
func)(dat->real, other),
834 (*
func)(dat->imag, other));
839 #define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
860 #define nucomp_quo nucomp_div
908 VALUE r, theta, nr, ntheta;
915 nr = m_exp_bang(
f_sub(
f_mul(dat->real, m_log_bang(r)),
916 f_mul(dat->imag, theta)));
918 f_mul(dat->imag, m_log_bang(r)));
944 f_mul(dat->imag, dat->imag)),
959 rb_warn(
"in a**b, b may be too big");
965 f_mul(theta, other));
1040 return m_hypot(dat->real, dat->imag);
1057 f_mul(dat->imag, dat->imag));
1074 return m_atan2_bang(dat->imag, dat->real);
1126 nucomp_true(
VALUE self)
1147 nucomp_exact_p(
VALUE self)
1155 nucomp_inexact_p(
VALUE self)
1243 #if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
1271 s = (*func)(dat->real);
1419 return f_to_i(dat->real);
1443 return f_to_f(dat->real);
1469 return f_to_r(dat->real);
1544 return (c ==
'-' || c ==
'+');
1564 return isdigit((
unsigned char)c);
1594 }
while (**s ==
'_');
1601 return (c ==
'e' || c ==
'E');
1676 return (c ==
'i' || c ==
'I' ||
1677 c ==
'j' || c ==
'J');
1687 if (strpbrk(s,
".eE"))
1694 VALUE *ret,
char **b)
1706 num =
INT2FIX((sign ==
'-') ? -1 : + 1);
1750 num2 =
INT2FIX((sign ==
'-') ? -1 : + 1);
1777 while (isspace((
unsigned char)**s))
1889 VALUE a1, a2, backref;
1956 (!f_real_p(a1) || !f_real_p(a2)))
2006 return f_mul(
self,
self);
2009 #define id_PI rb_intern("PI")
2119 #define rb_intern(str) rb_intern_const(str)
2121 assert(fprintf(stderr,
"assert() is now active\n"));
static int read_rat_nos(const char **s, int strict, char **b)
RUBY_EXTERN VALUE rb_cString
static VALUE nucomp_expt(VALUE self, VALUE other)
static int islettere(int c)
static VALUE nucomp_rationalize(int argc, VALUE *argv, VALUE self)
RUBY_EXTERN VALUE rb_cFloat
VALUE rb_num_coerce_bin(VALUE, VALUE, ID)
size_t strlen(const char *)
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_complex_new2(VALUE klass, VALUE x, VALUE y)
static VALUE f_signbit(VALUE 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_must_asciicompat(VALUE)
SSL_METHOD *(* func)(void)
static int read_rat(const char **s, int strict, char **b)
VALUE rb_str_concat(VALUE, VALUE)
st_index_t rb_memhash(const void *ptr, long len)
static VALUE nucomp_add(VALUE self, VALUE other)
VALUE rb_lcm(VALUE x, VALUE y)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
static VALUE string_to_c_strict(VALUE self)
static VALUE k_bignum_p(VALUE x)
static VALUE nucomp_to_s(VALUE self)
VALUE rb_backref_get(void)
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,...)
VALUE rb_ivar_get(VALUE, ID)
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)
static VALUE nucomp_negate(VALUE self)
static VALUE nucomp_mul(VALUE self, VALUE other)
double rb_str_to_dbl(VALUE, int)
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)
static VALUE nucomp_to_c(VALUE self)
static VALUE f_negative_p(VALUE x)
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 str2num(char *s)
static VALUE numeric_rect(VALUE self)
#define NEWOBJ_OF(obj, type, klass, flags)
VALUE rb_cstr_to_rat(const char *, int)
#define RB_TYPE_P(obj, type)
static VALUE nucomp_eqeq_p(VALUE self, VALUE other)
VALUE rb_math_log(int argc, VALUE *argv)
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)
RUBY_EXTERN VALUE rb_cObject
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 int parse_comp(const char *s, int strict, VALUE *num)
static VALUE nucomp_real(VALUE self)
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)
#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)
#define ALLOCV_N(type, v, n)
static VALUE f_sub(VALUE x, VALUE y)
#define RUBY_FUNC_EXPORTED
static int read_comp(const char **s, int strict, VALUE *ret, char **b)
static VALUE nucomp_fdiv(VALUE self, VALUE other)
VALUE rb_const_get(VALUE, ID)
#define rb_complex_new2(x, y)
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_ivar_set(VALUE, ID, VALUE)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
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 void skip_ws(const char **s)
static VALUE nucomp_numerator(VALUE self)
void rb_str_modify(VALUE)
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 nucomp_dumper(VALUE self)
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
static VALUE f_eqeq_p(VALUE x, VALUE y)
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)
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)
RUBY_EXTERN VALUE rb_cRational
#define assert(condition)
static VALUE f_complex_new_bang2(VALUE klass, VALUE x, VALUE y)
#define StringValuePtr(v)
static VALUE nucomp_coerce(VALUE self, VALUE other)
static int read_digits(const char **s, int strict, char **b)
static VALUE numeric_polar(VALUE self)
void rb_copy_generic_ivar(VALUE, VALUE)
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)
RUBY_EXTERN VALUE rb_cFixnum
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_warn(const char *fmt,...)
static int isdecimal(int c)
RUBY_EXTERN VALUE rb_cNilClass
double rb_cstr_to_dbl(const char *, int)
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)
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)