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
97 #ifndef PRESERVE_SIGNEDZERO
123 #ifndef PRESERVE_SIGNEDZERO
176 #define f_positive_p(x) (!f_negative_p(x))
195 #define f_nonzero_p(x) (!f_zero_p(x))
258 #define k_exact_p(x) (!k_float_p(x))
259 #define k_inexact_p(x) k_float_p(x)
261 #define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
262 #define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
264 #define get_dat1(x) \
265 struct RComplex *dat;\
266 dat = ((struct RComplex *)(x))
268 #define get_dat2(x,y) \
269 struct RComplex *adat, *bdat;\
270 adat = ((struct RComplex *)(x));\
271 bdat = ((struct RComplex *)(y))
329 #ifdef CANONICALIZATION_FOR_MATHN
334 static int canonicalization = 0;
339 canonicalization =
f;
364 if (
f_zero_p(imag) && canonicalization)
368 if (f_real_p(real) && f_real_p(imag))
370 else if (f_real_p(real)) {
374 f_sub(real, dat->imag),
377 else if (f_real_p(imag)) {
382 f_add(dat->imag, imag));
388 f_sub(adat->real, bdat->imag),
389 f_add(adat->imag, bdat->real));
468 inline static VALUE \
469 m_##n##_bang(VALUE x)\
471 return rb_math_##n(x);\
475 inline static VALUE \
476 m_##n##_bang(VALUE x, VALUE y)\
478 return rb_math_##n(x, y);\
487 #define m_hypot(x,y) m_hypot_bang((x),(y))
502 return m_cos_bang(x);
506 f_mul(m_cos_bang(dat->real),
507 m_cosh_bang(dat->imag)),
509 m_sinh_bang(dat->imag)));
517 return m_sin_bang(x);
521 f_mul(m_sin_bang(dat->real),
522 m_cosh_bang(dat->imag)),
523 f_mul(m_cos_bang(dat->real),
524 m_sinh_bang(dat->imag)));
536 return m_sqrt_bang(x);
543 return f_conj(m_sqrt(f_conj(x)));
651 real = (*func)(adat->real, bdat->real);
652 imag = (*func)(adat->imag, bdat->imag);
660 (*
func)(dat->real, other), dat->imag);
722 f_mul(adat->imag, bdat->imag));
724 f_mul(adat->imag, bdat->real));
732 f_mul(dat->real, other),
733 f_mul(dat->imag, other));
752 r = (*func)(bdat->imag, bdat->real);
760 f_mul(adat->imag, r)), n),
762 f_mul(adat->real, r)), n));
767 r = (*func)(bdat->real, bdat->imag);
784 (*
func)(dat->real, other),
785 (*
func)(dat->imag, other));
790 #define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by 0")
811 #define nucomp_quo nucomp_div
859 VALUE r, theta, nr, ntheta;
867 f_mul(dat->imag, theta)));
895 f_mul(dat->imag, dat->imag)),
910 rb_warn(
"in a**b, b may be too big");
916 f_mul(theta, other));
991 return m_hypot(dat->real, dat->imag);
1008 f_mul(dat->imag, dat->imag));
1025 return m_atan2_bang(dat->imag, dat->real);
1077 nucomp_true(
VALUE self)
1098 nucomp_exact_p(
VALUE self)
1106 nucomp_inexact_p(
VALUE self)
1194 #if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
1220 s = (*func)(dat->real);
1368 return f_to_i(dat->real);
1392 return f_to_f(dat->real);
1418 return f_to_r(dat->real);
1493 return (c ==
'-' || c ==
'+');
1513 return isdigit((
unsigned char)c);
1543 }
while (**s ==
'_');
1550 return (c ==
'e' || c ==
'E');
1625 return (c ==
'i' || c ==
'I' ||
1626 c ==
'j' || c ==
'J');
1636 if (strpbrk(s,
".eE"))
1655 num =
INT2FIX((sign ==
'-') ? -1 : + 1);
1699 num2 =
INT2FIX((sign ==
'-') ? -1 : + 1);
1726 while (isspace((
unsigned char)**s))
1838 VALUE a1, a2, backref;
1890 (!f_real_p(a1) || !f_real_p(a2)))
1940 return f_mul(
self,
self);
1943 #define id_PI rb_intern("PI")
2054 #define rb_intern(str) rb_intern_const(str)
2056 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)
rb_funcall2(argv[0], id_yield, argc-1, argv+1)
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)
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
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)
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_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)
#define RCOMPLEX_SET_REAL(cmp, r)
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)
#define RARRAY_AREF(a, i)
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)
#define RCOMPLEX_SET_IMAG(cmp, i)
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)
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_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)
#define RGENGC_WB_PROTECTED_COMPLEX
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)
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)
VALUE rb_complex_raw(VALUE x, VALUE y)
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)
rb_ivar_set(yielder, id_memo, LONG2NUM(++count))
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)
#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)