12 #define BSE_1_DIV_PI (0.3183098861837906715377675267450287240689) // 1/pi
13 #define BSE_PI_DIV_2 (1.570796326794896619231321691639751442099) // pi/2
14 #define BSE_2_DIV_PI (0.6366197723675813430755350534900574481378) // 2/pi
15 #define BSE_2_DIV_SQRT_PI (1.128379167095512573896158903121545171688) // 2/sqrt(pi)
16 #define BSE_2_DIV_LN2 (2.88539008177792681471984936200378427485329) // 2/ln(2)
17 #define BSE_PI_DIV_4 (0.7853981633974483096156608458198757210493) // pi/4
18 #define BSE_E (2.718281828459045235360287471352662497757) // e^1
19 #define BSE_LOG2E (1.442695040888963407359924681001892137427) // log_2(e^1)
20 #define BSE_LOG10E (0.4342944819032518276511289189166050822944) // log_10(e^1)
21 #define BSE_LN2 (0.6931471805599453094172321214581765680755) // ln(2)
22 #define BSE_SQRT2 (1.41421356237309504880168872420969807857) // sqrt(2)
23 #define BSE_1_DIV_SQRT2 (0.7071067811865475244008443621048490392848) // 1/sqrt(2)
24 #define BSE_LN4 (1.386294361119890618834464242916353136151) // ln(4)
25 #define BSE_LN10 (2.302585092994045684017991454684364207601) // ln(10)
26 #define BSE_LOG2_10 (3.321928094887362347870319429489390175865) // log_2(10)
27 #define BSE_LOG2POW20_10 (0.1660964047443681173935159714744695087932) // log_2(10)/20
28 #define BSE_2_POW_1_DIV_12 (1.059463094359295264561825294946341700779) // 2^(1/12)
29 #define BSE_LN_2_POW_1_DIV_12 (5.776226504666210911810267678818138067296e-2) // ln(2^(1/12))
30 #define BSE_LN_2_POW_1_DIV_1200_d (5.776226504666210911810267678818138067296e-4) // ln(2^(1/1200))
31 #define BSE_2_POW_1_DIV_72 (1.009673533228510862192521401118605073603) // 2^(1/72)
32 #define BSE_LN_2_POW_1_DIV_72 (9.62704417444368485301711279803023011216e-3) // ln(2^(1/72))
33 #define BSE_DECIBEL20_FACTOR (8.68588963806503655302257837833210164588794) // 20.0 / ln (10.0)
34 #define BSE_DECIBEL10_FACTOR (4.34294481903251827651128918916605082294397) // 10.0 / ln (10.0)
35 #define BSE_1_DIV_DECIBEL20_FACTOR (0.1151292546497022842008995727342182103801) // ln (10) / 20
36 #define BSE_COMPLEX_ONE (bse_complex (1, 0))
45 static inline BseComplex bse_complex (
double re,
47 static inline BseComplex bse_complex_polar (
double abs,
73 static inline double bse_complex_abs (
BseComplex c);
74 static inline double bse_complex_arg (
BseComplex c);
85 void bse_complex_gnuplot (
const char *file_name,
88 std::string bse_string_from_double (
long double value);
92 static inline void bse_poly_add (uint degree,
95 static inline void bse_poly_sub (uint order,
98 static inline void bse_poly_mul (
double *p,
103 static inline void bse_poly_scale (uint order,
106 static inline void bse_poly_xscale (uint order,
109 static inline double bse_poly_eval (uint degree,
112 void bse_poly_complex_roots (uint poly_degree,
115 void bse_poly_from_re_roots (uint poly_degree,
118 void bse_cpoly_from_roots (uint poly_degree,
121 static inline void bse_cpoly_mul_monomial (uint degree,
124 static inline void bse_cpoly_mul_reciprocal (uint degree,
127 static inline void bse_cpoly_mul (
BseComplex *p,
132 gboolean bse_poly2_droots (gdouble roots[2],
144 double bse_temp_freq (
double kammer_freq,
148 double bse_bit_depth_epsilon (guint n_bits);
149 gint bse_rand_int (
void);
150 gfloat bse_rand_float (
void);
151 gint bse_rand_bool (
void);
152 void bse_float_gnuplot (
const char *file_name,
156 const float *ypoints);
161 bse_complex (
double re,
170 bse_complex_polar (
double abs,
173 return bse_complex (abs * cos (arg), abs * sin (arg));
179 return bse_complex (c1.re + c2.re, c1.im + c2.im);
186 return bse_complex (c1.re + c2.re + c3.re, c1.im + c2.im + c3.im);
192 return bse_complex (c1.re - c2.re, c1.im - c2.im);
199 return bse_complex (c1.re - c2.re - c3.re, c1.im - c2.im - c3.im);
205 return bse_complex (c1.re * scale, c1.im * scale);
211 return bse_complex (c1.re * c2.re - c1.im * c2.im, c1.re * c2.im + c1.im * c2.re);
218 double aec = c1.re * c2.re * c3.re;
219 double bde = c1.im * c2.im * c3.re;
220 double adf = c1.re * c2.im * c3.im;
221 double bcf = c1.im * c2.re * c3.im;
222 double ade = c1.re * c2.im * c3.re;
223 double bce = c1.im * c2.re * c3.re;
224 double acf = c1.re * c2.re * c3.im;
225 double bdf = c1.im * c2.im * c3.im;
227 return bse_complex (aec - bde - adf - bcf, ade + bce + acf - bdf);
234 if (fabs (b.re) >=
fabs (b.im))
236 double r = b.im / b.re, den = b.re + r * b.im;
237 c.re = (a.re + r * a.im) / den;
238 c.im = (a.im - r * a.re) / den;
242 double r = b.re / b.im, den = b.im + r * b.re;
243 c.re = (a.re * r + a.im) / den;
244 c.im = (a.im * r - a.re) / den;
251 if (fabs (c.re) >=
fabs (c.im))
253 double r = c.im / c.re, den = c.re + r * c.im;
259 double r = c.re / c.im, den = c.im + r * c.re;
268 if (z.re == 0.0 && z.im == 0.0)
273 double w, x =
fabs (z.re), y =
fabs (z.im);
277 w =
sqrt (x) *
sqrt (0.5 * (1.0 + sqrt (1.0 + r * r)));
282 w =
sqrt (y) *
sqrt (0.5 * (r + sqrt (1.0 + r * r)));
287 c.im = z.im / (2.0 * w);
291 c.im = z.im >= 0 ? w : -w;
292 c.re = z.im / (2.0 * c.im);
300 return bse_complex (c.re, -c.im);
305 return bse_complex (-c.re, -c.im);
316 double absa =
fabs (c.re), absb =
fabs (c.im);
317 return (absa > absb ?
319 absa * sqrt (1.0 + (absb / absa) * (absb / absa)) :
321 absb * sqrt (1.0 + (absa / absb) * (absa / absb)));
326 double a =
atan2 (c.im, c.re);
332 return bse_complex (sin (c.re) *
cosh (c.im),
cos (c.re) *
sinh (c.im));
337 return bse_complex (cos (c.re) *
cosh (c.im), -
sin (c.re) *
sinh (c.im));
342 return bse_complex_div (bse_complex (tan (c.re),
tanh (c.im)),
343 bse_complex (1.0, -tan (c.re) *
tanh (c.im)));
348 return bse_complex (sinh (c.re) *
cos (c.im),
cosh (c.re) *
sin (c.im));
353 return bse_complex (cosh (c.re) *
cos (c.im),
sinh (c.re) *
sin (c.im));
358 return bse_complex_div (bse_complex_sinh (c),
359 bse_complex_cosh (c));
362 bse_poly_add (uint degree,
368 for (i = 0; i <= degree; i++)
372 bse_poly_sub (uint degree,
378 for (i = 0; i <= degree; i++)
382 bse_poly_mul (
double *p,
390 for (i = aorder + border; i > 0; i--)
395 for (j = i - MIN (border, i); j <= MIN (aorder, i); j++)
396 t += a[j] * b[i - j];
402 bse_cpoly_mul_monomial (uint degree,
408 c[degree] = c[degree - 1];
409 for (j = degree - 1; j >= 1; j--)
410 c[j] = bse_complex_sub (c[j - 1], bse_complex_mul (c[j], root));
411 c[0] = bse_complex_mul (c[0], bse_complex_inv (root));
414 bse_cpoly_mul_reciprocal (uint degree,
420 c[degree] = bse_complex_mul (c[degree - 1], bse_complex_inv (root));
421 for (j = degree - 1; j >= 1; j--)
422 c[j] = bse_complex_sub (c[j], bse_complex_mul (c[j - 1], root));
434 for (i = aorder + border; i > 0; i--)
439 t = bse_complex (0, 0);
440 for (j = i - MIN (i, border); j <= MIN (aorder, i); j++)
441 t = bse_complex_add (t, bse_complex_mul (a[j], b[i - j]));
444 p[0] = bse_complex_mul (a[0], b[0]);
447 bse_poly_scale (uint degree,
453 for (i = 0; i <= degree; i++)
457 bse_poly_xscale (uint degree,
461 double scale = xscale;
464 for (i = 1; i <= degree; i++)
471 bse_poly_eval (uint degree,
475 double sum = a[degree];
478 sum = sum * x + a[degree];
Definition: bsemath.hh:39