Canoe
Comprehensive Atmosphere N' Ocean Engine
core.h
Go to the documentation of this file.
1 #ifndef SRC_CLIMATH_CORE_H_
2 #define SRC_CLIMATH_CORE_H_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "math.h"
9 
10 struct float_triplet {
11  double x, y, z;
12 };
13 
14 inline double sqr(double x) { return x * x; }
15 inline double cub(double x) { return x * x * x; }
16 inline double min(double x1, double x2, double x3) {
17  return fmin(x1, fmin(x2, x3));
18 }
19 inline double max(double x1, double x2, double x3) {
20  return fmax(x1, fmax(x2, x3));
21 }
22 inline double allmax(double *a, int n) {
23  double v = a[0];
24  for (int i = 1; i < n; ++i)
25  if (v < a[i]) v = a[i];
26  return v;
27 }
28 inline double allmin(double *a, int n) {
29  double v = a[0];
30  for (int i = 1; i < n; ++i)
31  if (v > a[i]) v = a[i];
32  return v;
33 }
34 inline int sign(double x) { return x < 0. ? -1 : 1; }
35 
36 int fcmp(double x1, double x2);
37 
38 // unit conversion
39 
40 inline double rad2deg(double phi) { return phi * 180. / M_PI; }
41 inline double deg2rad(double phi) { return phi * M_PI / 180.; }
42 
43 inline double km2m(double x) { return x * 1.E3; }
44 inline double m2km(double x) { return x / 1.E3; }
45 
46 inline double day2sec(double x) { return x * 86400.; }
47 inline double sec2day(double x) { return x / 86400.; }
48 
49 inline double au2m(double x) { return x * 1.495978707E11; }
50 inline double m2au(double x) { return x / 1.495978707E11; }
51 
52 #ifdef __cplusplus
53 } /* extern "C" */
54 #endif
55 
56 #endif // SRC_CLIMATH_CORE_H_
int sign(double x)
Definition: core.h:34
double m2km(double x)
Definition: core.h:44
double deg2rad(double phi)
Definition: core.h:41
double sqr(double x)
Definition: core.h:14
double day2sec(double x)
Definition: core.h:46
double km2m(double x)
Definition: core.h:43
double min(double x1, double x2, double x3)
Definition: core.h:16
double max(double x1, double x2, double x3)
Definition: core.h:19
int fcmp(double x1, double x2)
Definition: fcmp.c:34
double au2m(double x)
Definition: core.h:49
double cub(double x)
Definition: core.h:15
double allmin(double *a, int n)
Definition: core.h:28
double allmax(double *a, int n)
Definition: core.h:22
double m2au(double x)
Definition: core.h:50
double sec2day(double x)
Definition: core.h:47
double rad2deg(double phi)
Definition: core.h:40
double y
Definition: core.h:11
double z
Definition: core.h:11
double x
Definition: core.h:11