Adopt use of gnulib for portability.
[pspp-builds.git] / src / expressions / helpers.h
1 #ifndef EXPRESSIONS_HELPERS_H 
2 #define EXPRESSIONS_HELPERS_H
3
4 #include <ctype.h>
5 #include <float.h>
6 #include <gsl/gsl_cdf.h>
7 #include <gsl/gsl_randist.h>
8 #include <gsl/gsl_sf.h>
9 #include <limits.h>
10 #include <math.h>
11 #include <stdbool.h>
12 #include "case.h"
13 #include "data-in.h"
14 #include "dictionary.h"
15 #include "error.h"
16 #include "calendar.h"
17 #include "gsl-extras/gsl-extras.h"
18 #include "misc.h"
19 #include "moments.h"
20 #include "settings.h"
21 #include "str.h"
22 #include "val.h"
23 #include "var.h"
24 #include "vfm.h"
25
26 #include "gettext.h"
27 #define _(msgid) gettext (msgid)
28
29 static inline double check_errno (double x) 
30 {
31   return errno == 0 ? x : SYSMIS;
32 }
33
34 #define check_errno(EXPRESSION) (errno = 0, check_errno (EXPRESSION))
35
36 #define DAY_S (60. * 60. * 24.)         /* Seconds per day. */
37 #define DAY_H 24.                       /* Hours per day. */
38 #define H_S (60 * 60.)                  /* Seconds per hour. */
39 #define H_MIN 60.                       /* Minutes per hour. */
40 #define MIN_S 60.                       /* Seconds per minute. */
41 #define WEEK_DAY 7.                     /* Days per week. */
42
43 extern const struct fixed_string empty_string;
44
45 int compare_string (const struct fixed_string *, const struct fixed_string *);
46
47 double expr_ymd_to_date (double year, double month, double day);
48 double expr_ymd_to_ofs (double year, double month, double day);
49 double expr_wkyr_to_date (double wk, double yr);
50 double expr_yrday_to_date (double yr, double day);
51 double expr_yrmoda (double year, double month, double day);
52
53 struct fixed_string alloc_string (struct expression *, size_t length);
54 struct fixed_string copy_string (struct expression *,
55                                  const char *, size_t length);
56
57 static inline bool
58 is_valid (double d) 
59 {
60   return finite (d) && d != SYSMIS;
61 }
62
63 size_t count_valid (double *, size_t);
64
65 double idf_beta (double P, double a, double b);
66 double ncdf_beta (double x, double a, double b, double lambda);
67 double npdf_beta (double x, double a, double b, double lambda);
68
69 double cdf_bvnor (double x0, double x1, double r);
70
71 double idf_fdist (double P, double a, double b);
72
73 #endif /* expressions/helpers.h */