amath  1.8.5
Simple command line calculator
prim.c File Reference
#include "prim.h"
Include dependency graph for prim.c:

Go to the source code of this file.

Macros

#define REAL_PART(z)   ((z).parts[0])
 
#define IMAG_PART(z)   ((z).parts[1])
 

Functions

double creal (complex z)
 Real part of complex number. More...
 
double cimag (complex z)
 Imaginary part of complex number. More...
 
double cabs (complex z)
 Absolute value of complex number. More...
 
complex conj (complex z)
 
complex cpack (double x, double y)
 Pack two real numbers into a complex number. More...
 
complex ctrunc (complex z)
 Truncated value of complex number. More...
 
complex cfloor (complex z)
 Floor value of complex number. More...
 
complex cceil (complex z)
 Ceiling value of complex number. More...
 
complex cround (complex z)
 Division of two complex numbers. More...
 
complex cadd (complex y, complex z)
 Addition of two complex numbers. More...
 
complex csub (complex y, complex z)
 Subtraction of two complex numbers. More...
 
complex cmul (complex y, complex z)
 Multiplication of two complex numbers. More...
 
complex cdiv (complex y, complex z)
 Division of two complex numbers. More...
 
complex creci (complex z)
 Reciprocal value of complex number. More...
 
void cchsh (double x, double *c, double *s)
 Calculate cosh and sinh. More...
 
void cchc (double x, double *ch, double *c)
 Calculate cosh and cos. More...
 

Macro Definition Documentation

◆ IMAG_PART

#define IMAG_PART (   z)    ((z).parts[1])

Definition at line 33 of file prim.c.

◆ REAL_PART

#define REAL_PART (   z)    ((z).parts[0])

Definition at line 32 of file prim.c.

Function Documentation

◆ cabs()

double cabs ( complex  z)

Absolute value of complex number.

Definition at line 54 of file prim.c.

References cimag(), creal(), and hypot().

Referenced by ComplexNumber::Absolute(), clog(), cpow(), and csqrt().

55 {
56  return hypot(creal(z), cimag(z));
57 }
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
double hypot(double x, double y)
hypot
Definition: hypot.c:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadd()

complex cadd ( complex  y,
complex  z 
)

Addition of two complex numbers.

Definition at line 120 of file prim.c.

References cimag(), cpack(), and creal().

Referenced by ComplexNumber::Add(), cacos(), cacosh(), cacot(), cacoth(), cacsc(), cacsch(), casec(), casech(), casin(), casinh(), catan(), and catanh().

121 {
122  complex w;
123  w = cpack(creal(y) + creal(z), cimag(y) + cimag(z));
124  return w;
125 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cceil()

complex cceil ( complex  z)

Ceiling value of complex number.

Definition at line 100 of file prim.c.

References ceil(), cimag(), cpack(), and creal().

Referenced by ComplexNumber::Ceiling().

101 {
102  complex w;
103  w = cpack(ceil(creal(z)), ceil(cimag(z)));
104  return w;
105 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double ceil(double x)
Ceiling function.
Definition: ceil.c:63
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cchc()

void cchc ( double  x,
double *  ch,
double *  c 
)

Calculate cosh and cos.

Definition at line 219 of file prim.c.

References cos(), and cosh().

220 {
221  *ch = cosh(2.0 * x);
222  *c = cos(2.0 * x);
223 }
double cosh(double x)
Hyperbolic cosine function.
Definition: cosh.c:83
double cos(double x)
Cosine function.
Definition: cos.c:87
Here is the call graph for this function:

◆ cchsh()

void cchsh ( double  x,
double *  c,
double *  s 
)

Calculate cosh and sinh.

Definition at line 197 of file prim.c.

References cosh(), exp(), fabs(), and sinh().

Referenced by ccos(), ccosh(), csin(), and csinh().

198 {
199  double e, ei;
200 
201  if (fabs(x) <= 0.5)
202  {
203  *c = cosh(x);
204  *s = sinh(x);
205  }
206  else
207  {
208  e = exp(x);
209  ei = 0.5 / e;
210  e = 0.5 * e;
211  *s = e - ei;
212  *c = e + ei;
213  }
214 }
double cosh(double x)
Hyperbolic cosine function.
Definition: cosh.c:83
double sinh(double x)
Hyperbolic sine function.
Definition: sinh.c:77
double exp(double x)
Returns the exponential of x.
Definition: exp.c:138
double fabs(double x)
Returns the absolute value of x.
Definition: fabs.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cdiv()

complex cdiv ( complex  y,
complex  z 
)

Division of two complex numbers.

Definition at line 159 of file prim.c.

References cimag(), cpack(), and creal().

Referenced by cacot(), cacsc(), casec(), catan(), clog10(), clogb(), and ComplexNumber::Div().

160 {
161  complex w;
162  double a, b, c, d;
163  double q, v, x;
164 
165  a = creal(y);
166  b = cimag(y);
167  c = creal(z);
168  d = cimag(z);
169 
170  q = c * c + d * d;
171  v = a * c + b * d;
172  x = b * c - a * d;
173 
174  w = cpack(v / q, x / q);
175  return w;
176 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cfloor()

complex cfloor ( complex  z)

Floor value of complex number.

Definition at line 90 of file prim.c.

References cimag(), cpack(), creal(), and floor().

Referenced by ComplexNumber::Floor().

91 {
92  complex w;
93  w = cpack(floor(creal(z)), floor(cimag(z)));
94  return w;
95 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
double floor(double x)
Floor function.
Definition: floor.c:62
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cimag()

◆ cmul()

complex cmul ( complex  y,
complex  z 
)

Multiplication of two complex numbers.

Definition at line 140 of file prim.c.

References cimag(), cpack(), and creal().

Referenced by cacos(), cacosh(), cacot(), cacoth(), cacsc(), cacsch(), casec(), casech(), casin(), casinh(), catan(), catanh(), ccbrt(), and ComplexNumber::Mul().

141 {
142  complex w;
143  double a, b, c, d;
144 
145  // (a+bi)(c+di)
146  a = creal(y);
147  b = cimag(y);
148  c = creal(z);
149  d = cimag(z);
150 
151  // (ac -bd) + (ad + bc)i
152  w = cpack(a * c - b * d, a * d + b * c);
153  return w;
154 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conj()

complex conj ( complex  z)

Definition at line 59 of file prim.c.

References cpack().

Referenced by creci().

60 {
61  IMAG_PART(z) = -IMAG_PART(z);
62  return cpack(REAL_PART(z), IMAG_PART(z));
63 }
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
#define REAL_PART(z)
Definition: prim.c:32
#define IMAG_PART(z)
Definition: prim.c:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpack()

complex cpack ( double  x,
double  y 
)

Pack two real numbers into a complex number.

Definition at line 68 of file prim.c.

Referenced by ComplexNumber::Add(), cacos(), cacosh(), cacot(), cacoth(), cacsc(), cacsch(), cadd(), casec(), casech(), casin(), casinh(), catan(), catanh(), ccbrt(), cceil(), ccos(), ccosh(), ccot(), ccoth(), ccsc(), ccsch(), cdiv(), cexp(), cfloor(), clog(), clog10(), clogb(), cmul(), ComplexNumber::ComplexNumber(), conj(), cpow(), creci(), cround(), csec(), csech(), csin(), csinh(), csqrt(), csub(), ctan(), ctanh(), ctrunc(), ComplexNumber::Div(), ComplexNumber::Mul(), ComplexNumber::Raise(), ComplexNumber::Sub(), and ComplexNumber::Unary().

69 {
70  complex z;
71 
72  REAL_PART(z) = x;
73  IMAG_PART(z) = y;
74  return (z);
75 }
Definition: mathi.h:48
#define REAL_PART(z)
Definition: prim.c:32
#define IMAG_PART(z)
Definition: prim.c:33
Here is the caller graph for this function:

◆ creal()

◆ creci()

complex creci ( complex  z)

Reciprocal value of complex number.

Definition at line 181 of file prim.c.

References cimag(), conj(), cpack(), and creal().

Referenced by cacsch(), casec(), casech(), and ComplexNumber::Reciprocal().

182 {
183  complex w;
184  double q, a, b;
185 
186  a = creal(z);
187  b = cimag(conj(z));
188  q = a * a + b * b;
189  w = cpack(a / q, b / q);
190 
191  return w;
192 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
complex conj(complex z)
Definition: prim.c:59
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cround()

complex cround ( complex  z)

Division of two complex numbers.

Definition at line 110 of file prim.c.

References cimag(), cpack(), creal(), and round().

Referenced by ComplexNumber::Round().

111 {
112  complex w;
113  w = cpack(round(creal(z)), round(cimag(z)));
114  return w;
115 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
double round(double x)
Round function.
Definition: round.c:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ csub()

complex csub ( complex  y,
complex  z 
)

Subtraction of two complex numbers.

Definition at line 130 of file prim.c.

References cimag(), cpack(), and creal().

Referenced by cacos(), cacosh(), cacot(), cacoth(), cacsc(), casec(), casech(), casin(), catan(), catanh(), and ComplexNumber::Sub().

131 {
132  complex w;
133  w = cpack(creal(y) - creal(z), cimag(y) - cimag(z));
134  return w;
135 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctrunc()

complex ctrunc ( complex  z)

Truncated value of complex number.

Definition at line 80 of file prim.c.

References cimag(), cpack(), creal(), and trunc().

Referenced by ComplexNumber::Trunc().

81 {
82  complex w;
83  w = cpack(trunc(creal(z)), trunc(cimag(z)));
84  return w;
85 }
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
double trunc(double x)
Truncate function.
Definition: trunc.c:52
Here is the call graph for this function:
Here is the caller graph for this function: