Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
Macros | Functions | Variables
complex.c File Reference
#include "ruby/internal/config.h"
#include <ctype.h>
#include <math.h>
#include "id.h"
#include "internal.h"
#include "internal/array.h"
#include "internal/class.h"
#include "internal/complex.h"
#include "internal/numeric.h"
#include "internal/object.h"
#include "internal/rational.h"
#include "ruby_assert.h"

Go to the source code of this file.

Macros

#define _USE_MATH_DEFINES   1
 
#define NDEBUG
 
#define ZERO   INT2FIX(0)
 
#define ONE   INT2FIX(1)
 
#define TWO   INT2FIX(2)
 
#define id_to_i   idTo_i
 
#define id_to_r   idTo_r
 
#define id_negate   idUMinus
 
#define id_expt   idPow
 
#define id_to_f   idTo_f
 
#define id_quo   idQuo
 
#define id_fdiv   idFdiv
 
#define f_boolcast(x)   ((x) ? Qtrue : Qfalse)
 
#define fun1(n)
 
#define fun2(n)
 
#define PRESERVE_SIGNEDZERO
 
#define f_positive_p(x)   (!f_negative_p(x))
 
#define f_nonzero_p(x)   (!f_zero_p(x))
 
#define k_exact_p(x)   (!RB_FLOAT_TYPE_P(x))
 
#define k_exact_zero_p(x)   (k_exact_p(x) && f_zero_p(x))
 
#define get_dat1(x)    struct RComplex *dat = RCOMPLEX(x)
 
#define get_dat2(x, y)    struct RComplex *adat = RCOMPLEX(x), *bdat = RCOMPLEX(y)
 
#define imp1(n)
 
#define cospi(x)   cos((x) * M_PI)
 
#define sinpi(x)   sin((x) * M_PI)
 
#define rb_raise_zerodiv()   rb_raise(rb_eZeroDivError, "divided by 0")
 
#define nucomp_quo   rb_complex_div
 
#define FINITE_TYPE_P(v)   (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))
 

Functions

 fun1 (to_r)
 
 fun2 (expt)
 
VALUE rb_flo_is_finite_p (VALUE num)
 
VALUE rb_flo_is_infinite_p (VALUE num)
 
 imp1 (cos)
 
 imp1 (sin)
 
VALUE rb_dbl_complex_new_polar_pi (double abs, double ang)
 
VALUE rb_complex_real (VALUE self)
 
VALUE rb_complex_imag (VALUE self)
 
VALUE rb_complex_uminus (VALUE self)
 
VALUE rb_complex_plus (VALUE self, VALUE other)
 
VALUE rb_complex_minus (VALUE self, VALUE other)
 
VALUE rb_complex_mul (VALUE self, VALUE other)
 
VALUE rb_complex_div (VALUE self, VALUE other)
 
VALUE rb_complex_pow (VALUE self, VALUE other)
 
VALUE rb_complex_abs (VALUE self)
 
VALUE rb_complex_arg (VALUE self)
 
VALUE rb_complex_conjugate (VALUE self)
 
st_index_t rb_complex_hash (VALUE self)
 
VALUE rb_complex_raw (VALUE x, VALUE y)
 
VALUE rb_complex_new (VALUE x, VALUE y)
 
VALUE rb_complex_new_polar (VALUE x, VALUE y)
 
VALUE rb_complex_polar (VALUE x, VALUE y)
 
VALUE rb_Complex (VALUE x, VALUE y)
 
VALUE rb_dbl_complex_new (double real, double imag)
 Creates a Complex object. More...
 
void Init_Complex (void)
 

Variables

VALUE rb_cComplex
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES   1

Definition at line 12 of file complex.c.

◆ cospi

#define cospi (   x)    cos((x) * M_PI)

Definition at line 660 of file complex.c.

◆ f_boolcast

#define f_boolcast (   x)    ((x) ? Qtrue : Qfalse)

Definition at line 59 of file complex.c.

◆ f_nonzero_p

#define f_nonzero_p (   x)    (!f_zero_p(x))

Definition at line 343 of file complex.c.

◆ f_positive_p

#define f_positive_p (   x)    (!f_negative_p(x))

Definition at line 325 of file complex.c.

◆ FINITE_TYPE_P

#define FINITE_TYPE_P (   v)    (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))

Definition at line 1446 of file complex.c.

◆ fun1

#define fun1 (   n)
Value:
inline static VALUE \
f_##n(VALUE x)\
{\
return rb_funcall(x, id_##n, 0);\
}
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:1077
unsigned long VALUE
Definition: value.h:38

Definition at line 61 of file complex.c.

◆ fun2

#define fun2 (   n)
Value:
inline static VALUE \
f_##n(VALUE x, VALUE y)\
{\
return rb_funcall(x, id_##n, 1, y);\
}

Definition at line 68 of file complex.c.

◆ get_dat1

#define get_dat1 (   x)     struct RComplex *dat = RCOMPLEX(x)

Definition at line 393 of file complex.c.

◆ get_dat2

#define get_dat2 (   x,
 
)     struct RComplex *adat = RCOMPLEX(x), *bdat = RCOMPLEX(y)

Definition at line 396 of file complex.c.

◆ id_expt

#define id_expt   idPow

Definition at line 54 of file complex.c.

◆ id_fdiv

#define id_fdiv   idFdiv

Definition at line 57 of file complex.c.

◆ id_negate

#define id_negate   idUMinus

Definition at line 53 of file complex.c.

◆ id_quo

#define id_quo   idQuo

Definition at line 56 of file complex.c.

◆ id_to_f

#define id_to_f   idTo_f

Definition at line 55 of file complex.c.

◆ id_to_i

#define id_to_i   idTo_i

Definition at line 51 of file complex.c.

◆ id_to_r

#define id_to_r   idTo_r

Definition at line 52 of file complex.c.

◆ imp1

#define imp1 (   n)
Value:
inline static VALUE \
m_##n##_bang(VALUE x)\
{\
return rb_math_##n(x);\
}

Definition at line 567 of file complex.c.

◆ k_exact_p

#define k_exact_p (   x)    (!RB_FLOAT_TYPE_P(x))

Definition at line 389 of file complex.c.

◆ k_exact_zero_p

#define k_exact_zero_p (   x)    (k_exact_p(x) && f_zero_p(x))

Definition at line 391 of file complex.c.

◆ NDEBUG

#define NDEBUG

Definition at line 19 of file complex.c.

◆ nucomp_quo

#define nucomp_quo   rb_complex_div

Definition at line 962 of file complex.c.

◆ ONE

#define ONE   INT2FIX(1)

Definition at line 32 of file complex.c.

◆ PRESERVE_SIGNEDZERO

#define PRESERVE_SIGNEDZERO

Definition at line 75 of file complex.c.

◆ rb_raise_zerodiv

#define rb_raise_zerodiv ( )    rb_raise(rb_eZeroDivError, "divided by 0")

Definition at line 941 of file complex.c.

◆ sinpi

#define sinpi (   x)    sin((x) * M_PI)

Definition at line 665 of file complex.c.

◆ TWO

#define TWO   INT2FIX(2)

Definition at line 33 of file complex.c.

◆ ZERO

#define ZERO   INT2FIX(0)

Definition at line 31 of file complex.c.

Function Documentation

◆ fun1()

fun1 ( to_r  )

Definition at line 285 of file complex.c.

References FIXNUM_P, NUM2DBL, and rb_equal().

◆ fun2()

fun2 ( expt  )

Definition at line 297 of file complex.c.

References id_quo, rb_float_div(), rb_funcallv, RB_INTEGER_TYPE_P, rb_numeric_quo(), and T_RATIONAL.

◆ imp1() [1/2]

imp1 ( cos  )

Definition at line 574 of file complex.c.

References rb_math_log().

◆ imp1() [2/2]

imp1 ( sin  )

Definition at line 584 of file complex.c.

References f_mul, f_negate, get_dat1, rb_cComplex, and T_COMPLEX.

◆ Init_Complex()

void Init_Complex ( void  )

◆ rb_Complex()

VALUE rb_Complex ( VALUE  x,
VALUE  y 
)

Definition at line 1560 of file complex.c.

References rb_cComplex.

◆ rb_complex_abs()

VALUE rb_complex_abs ( VALUE  self)

Definition at line 1170 of file complex.c.

References f_abs, get_dat1, and rb_math_hypot().

Referenced by Init_Complex().

◆ rb_complex_arg()

VALUE rb_complex_arg ( VALUE  self)

Definition at line 1217 of file complex.c.

References get_dat1, and rb_math_atan2().

Referenced by Init_Complex().

◆ rb_complex_conjugate()

VALUE rb_complex_conjugate ( VALUE  self)

Definition at line 1263 of file complex.c.

References CLASS_OF, f_negate, and get_dat1.

Referenced by Init_Complex().

◆ rb_complex_div()

VALUE rb_complex_div ( VALUE  self,
VALUE  other 
)

Definition at line 957 of file complex.c.

References f_quo, and id_quo.

Referenced by Init_Complex(), and rb_numeric_quo().

◆ rb_complex_hash()

st_index_t rb_complex_hash ( VALUE  self)

Definition at line 1332 of file complex.c.

References get_dat1, NUM2LONG, rb_hash(), and rb_memhash().

◆ rb_complex_imag()

VALUE rb_complex_imag ( VALUE  self)

Definition at line 752 of file complex.c.

References get_dat1.

Referenced by Init_Complex().

◆ rb_complex_minus()

VALUE rb_complex_minus ( VALUE  self,
VALUE  other 
)

Definition at line 821 of file complex.c.

References CLASS_OF, f_sub, get_dat1, get_dat2, rb_num_coerce_bin(), and T_COMPLEX.

Referenced by Init_Complex().

◆ rb_complex_mul()

VALUE rb_complex_mul ( VALUE  self,
VALUE  other 
)

Definition at line 881 of file complex.c.

References CLASS_OF, f_mul, get_dat1, get_dat2, rb_num_coerce_bin(), and T_COMPLEX.

Referenced by Init_Complex().

◆ rb_complex_new()

VALUE rb_complex_new ( VALUE  x,
VALUE  y 
)

Definition at line 1542 of file complex.c.

References rb_cComplex.

Referenced by rb_dbl_complex_new_polar_pi().

◆ rb_complex_new_polar()

VALUE rb_complex_new_polar ( VALUE  x,
VALUE  y 
)

Definition at line 1548 of file complex.c.

References rb_cComplex.

Referenced by rb_complex_polar().

◆ rb_complex_plus()

VALUE rb_complex_plus ( VALUE  self,
VALUE  other 
)

Definition at line 787 of file complex.c.

References CLASS_OF, f_add, get_dat1, get_dat2, rb_num_coerce_bin(), and T_COMPLEX.

Referenced by Init_Complex().

◆ rb_complex_polar()

VALUE rb_complex_polar ( VALUE  x,
VALUE  y 
)

Definition at line 1554 of file complex.c.

References rb_complex_new_polar().

◆ rb_complex_pow()

VALUE rb_complex_pow ( VALUE  self,
VALUE  other 
)

◆ rb_complex_raw()

VALUE rb_complex_raw ( VALUE  x,
VALUE  y 
)

Definition at line 1536 of file complex.c.

References rb_cComplex.

Referenced by rb_dbl_complex_new().

◆ rb_complex_real()

VALUE rb_complex_real ( VALUE  self)

Definition at line 735 of file complex.c.

References get_dat1.

Referenced by Init_Complex().

◆ rb_complex_uminus()

VALUE rb_complex_uminus ( VALUE  self)

Definition at line 767 of file complex.c.

References CLASS_OF, f_negate, and get_dat1.

Referenced by Init_Complex().

◆ rb_dbl_complex_new()

VALUE rb_dbl_complex_new ( double  real,
double  imag 
)

Creates a Complex object.

Parameters
realreal part value
imagimaginary part value
Returns
a new Complex object

Definition at line 1576 of file complex.c.

References DBL2NUM, and rb_complex_raw().

◆ rb_dbl_complex_new_polar_pi()

VALUE rb_dbl_complex_new_polar_pi ( double  abs,
double  ang 
)

Definition at line 669 of file complex.c.

References cospi, DBL2NUM, rb_complex_new(), and sinpi.

Referenced by rb_big_pow(), and rb_float_pow().

◆ rb_flo_is_finite_p()

VALUE rb_flo_is_finite_p ( VALUE  num)

Definition at line 1804 of file numeric.c.

References isfinite, isinf(), isnan, num, Qfalse, Qtrue, and RFLOAT_VALUE.

Referenced by Init_Numeric().

◆ rb_flo_is_infinite_p()

VALUE rb_flo_is_infinite_p ( VALUE  num)

Definition at line 1784 of file numeric.c.

References INT2FIX, isinf(), num, Qnil, and RFLOAT_VALUE.

Referenced by Init_Numeric().

Variable Documentation

◆ rb_cComplex

VALUE rb_cComplex