5 operator ADD (a, b) = a + b;
6 operator SUB (a, b) = a - b;
8 absorb_miss operator MUL (a, b)
9 = (a == 0. || b == 0. ? 0.
10 : a == SYSMIS || b == SYSMIS ? SYSMIS
13 absorb_miss operator DIV (a, b)
15 : a == SYSMIS || b == SYSMIS ? SYSMIS
18 absorb_miss operator POW (a, b)
19 = (a == SYSMIS ? (b == 0. ? 1. : a)
20 : b == SYSMIS ? (a == 0. ? 0. : SYSMIS)
21 : a == 0. && b <= 0. ? SYSMIS
24 absorb_miss boolean operator AND (boolean a, boolean b)
27 : b == SYSMIS ? SYSMIS
30 absorb_miss boolean operator OR (boolean a, boolean b)
33 : b == SYSMIS ? SYSMIS
36 boolean operator NOT (boolean a)
41 // Numeric relational operators.
42 boolean operator EQ (a, b) = a == b;
43 boolean operator GE (a, b) = a >= b;
44 boolean operator GT (a, b) = a > b;
45 boolean operator LE (a, b) = a <= b;
46 boolean operator LT (a, b) = a < b;
47 boolean operator NE (a, b) = a != b;
49 // String relational operators.
50 boolean operator EQ_STRING (string a, string b) = compare_string (&a, &b) == 0;
51 boolean operator GE_STRING (string a, string b) = compare_string (&a, &b) >= 0;
52 boolean operator GT_STRING (string a, string b) = compare_string (&a, &b) > 0;
53 boolean operator LE_STRING (string a, string b) = compare_string (&a, &b) <= 0;
54 boolean operator LT_STRING (string a, string b) = compare_string (&a, &b) < 0;
55 boolean operator NE_STRING (string a, string b) = compare_string (&a, &b) != 0;
58 function ABS (x) = fabs (x);
59 extension function ACOS (x >= -1 && x <= 1) = acos (x);
60 function ASIN (x >= -1 && x <= 1) = asin (x);
61 function ATAN (x) = atan (x);
62 extension function ARCOS (x >= -1 && x <= 1) = acos (x);
63 function ARSIN (x >= -1 && x <= 1) = asin (x);
64 function ARTAN (x) = atan (x);
65 function COS (x) = cos (x);
66 function EXP (x) = check_errno (exp (x));
67 function LG10(x) = check_errno (log10 (x));
68 function LN (x) = check_errno (log (x));
69 function LNGAMMA (x >= 0) = gsl_sf_lngamma (x);
70 function MOD10 (x) = fmod (x, 10);
71 function RND (x) = x >= 0. ? floor (x + .5) : -floor (-x + .5);
72 function SIN (x) = sin (x);
73 function SQRT (x >= 0) = sqrt (x);
74 function TAN (x) = check_errno (tan (x));
75 function TRUNC (x) = x >= 0. ? floor (x) : -floor (-x);
77 absorb_miss function MOD (n, d)
80 return n != SYSMIS ? fmod (n, d) : SYSMIS;
82 return n != 0. ? SYSMIS : 0.;
85 // N-ary numeric functions.
86 absorb_miss boolean function ANY (x != SYSMIS, a[n])
91 for (i = 0; i < n; i++)
94 else if (a[i] == SYSMIS)
97 return sysmis ? SYSMIS : 0.;
100 boolean function ANY (string x, string a[n])
104 for (i = 0; i < n; i++)
105 if (!compare_string (&x, &a[i]))
110 function CFVAR.2 (a[n])
112 double mean, variance;
114 moments_of_doubles (a, n, NULL, &mean, &variance, NULL, NULL);
116 if (mean == SYSMIS || mean == 0 || variance == SYSMIS)
119 return sqrt (variance) / mean;
122 function MAX.1 (a[n])
128 for (i = 0; i < n; i++)
129 if (a[i] != SYSMIS && a[i] > max)
134 string function MAX (string a[n])
136 struct fixed_string *max;
140 for (i = 1; i < n; i++)
141 if (compare_string (&a[i], max) > 0)
146 function MEAN.1 (a[n])
149 moments_of_doubles (a, n, NULL, &mean, NULL, NULL, NULL);
153 function MIN.1 (a[n])
159 for (i = 0; i < n; i++)
160 if (a[i] != SYSMIS && a[i] < min)
165 string function MIN (string a[n])
167 struct fixed_string *min;
171 for (i = 1; i < n; i++)
172 if (compare_string (&a[i], min) < 0)
177 absorb_miss function NMISS (a[n])
180 size_t missing_cnt = 0;
182 for (i = 0; i < n; i++)
183 missing_cnt += a[i] == SYSMIS;
187 absorb_miss function NVALID (a[n])
190 size_t valid_cnt = 0;
192 for (i = 0; i < n; i++)
193 valid_cnt += a[i] != SYSMIS;
197 absorb_miss boolean function RANGE (x != SYSMIS, a[n*2])
202 for (i = 0; i < n; i++)
205 double y = a[2 * i + 1];
206 if (w != SYSMIS && y != SYSMIS)
208 if (w <= x && x <= y)
214 return sysmis ? SYSMIS : 0.;
217 boolean function RANGE (string x, string a[n*2])
221 for (i = 0; i < n; i++)
223 struct fixed_string *w = &a[2 * i];
224 struct fixed_string *y = &a[2 * i + 1];
225 if (compare_string (w, &x) <= 0 && compare_string (&x, y) <= 0)
234 moments_of_doubles (a, n, NULL, NULL, &variance, NULL, NULL);
235 return sqrt (variance);
238 function SUM.1 (a[n])
244 for (i = 0; i < n; i++)
250 function VARIANCE.2 (a[n])
253 moments_of_doubles (a, n, NULL, NULL, &variance, NULL, NULL);
257 // Time construction & extraction functions.
258 function TIME.HMS (h, m, s)
260 if ((h > 0. || m > 0. || s > 0.) && (h < 0. || m < 0. || s < 0.))
262 msg (SW, _("TIME.HMS cannot mix positive and negative arguments."));
266 return H_S * h + MIN_S * m + s;
268 function TIME.DAYS (days) = days * DAY_S;
269 function CTIME.DAYS (time) = time / DAY_S;
270 function CTIME.HOURS (time) = time / H_S;
271 function CTIME.MINUTES (time) = time / MIN_S;
272 function CTIME.SECONDS (time) = time;
274 // Date construction functions.
275 function DATE.DMY (d, m, y) = expr_ymd_to_date (y, m, d);
276 function DATE.MDY (m, d, y) = expr_ymd_to_date (y, m, d);
277 function DATE.MOYR (m, y) = expr_ymd_to_date (y, m, 1);
278 function DATE.QYR (q, y) = expr_ymd_to_date (y, q * 3 - 2, 1);
279 function DATE.WKYR (w, y) = expr_wkyr_to_date (w, y);
280 function DATE.YRDAY (y, yday) = expr_yrday_to_date (y, yday);
281 function YRMODA (y, m, d) = expr_yrmoda (y, m, d);
283 // Date extraction functions.
284 function XDATE.TDAY (date) = floor (date / DAY_S);
285 function XDATE.HOUR (date) = fmod (floor (date / H_S), DAY_H);
286 function XDATE.MINUTE (date) = fmod (floor (date / H_MIN), H_MIN);
287 function XDATE.SECOND (date) = fmod (date, MIN_S);
288 function XDATE.DATE (date) = floor (date / DAY_S) * DAY_S;
289 function XDATE.TIME (date) = fmod (date, DAY_S);
291 function XDATE.JDAY (date >= DAY_S) = calendar_offset_to_yday (date / DAY_S);
292 function XDATE.MDAY (date >= DAY_S) = calendar_offset_to_mday (date / DAY_S);
293 function XDATE.MONTH (date >= DAY_S)
294 = calendar_offset_to_month (date / DAY_S);
295 function XDATE.QUARTER (date >= DAY_S)
296 = (calendar_offset_to_month (date / DAY_S) - 1) / 3 + 1;
297 function XDATE.WEEK (date >= DAY_S)
298 = (calendar_offset_to_yday (date / DAY_S) - 1) / 7 + 1;
299 function XDATE.WKDAY (date >= DAY_S) = calendar_offset_to_wday (date / DAY_S);
300 function XDATE.YEAR (date >= DAY_S) = calendar_offset_to_year (date / DAY_S);
303 string function CONCAT (string a[n])
306 struct fixed_string dst;
309 dst = alloc_string (e, 255);
311 for (i = 0; i < n; i++)
313 struct fixed_string *src = &a[i];
316 copy_len = src->length;
317 if (dst.length + copy_len > 255)
318 copy_len = 255 - dst.length;
319 memcpy (&dst.string[dst.length], src->string, copy_len);
320 dst.length += copy_len;
326 function INDEX (string haystack, string needle)
328 if (needle.length == 0)
332 int limit = haystack.length - needle.length + 1;
334 for (i = 1; i <= limit; i++)
335 if (!memcmp (&haystack.string[i - 1], needle.string, needle.length))
341 function INDEX (string haystack, string needles, needle_len_d)
343 if (needle_len_d <= INT_MIN || needle_len_d >= INT_MAX
344 || (int) needle_len_d != needle_len_d
345 || needles.length == 0)
349 int needle_len = needle_len_d;
350 if (needle_len < 0 || needle_len > needles.length
351 || needles.length % needle_len != 0)
355 int limit = haystack.length - needle_len + 1;
357 for (i = 1; i <= limit; i++)
358 for (j = 0; j < needles.length; j += needle_len)
359 if (!memcmp (&haystack.string[i - 1], &needles.string[j],
368 function RINDEX (string haystack, string needle)
370 if (needle.length == 0)
374 int limit = haystack.length - needle.length + 1;
376 for (i = limit; i >= 1; i--)
377 if (!memcmp (&haystack.string[i - 1], needle.string, needle.length))
383 function RINDEX (string haystack, string needles, needle_len_d)
385 if (needle_len_d <= INT_MIN || needle_len_d >= INT_MAX
386 || (int) needle_len_d != needle_len_d
387 || needles.length == 0)
391 int needle_len = needle_len_d;
392 if (needle_len < 0 || needle_len > needles.length
393 || needles.length % needle_len != 0)
397 int limit = haystack.length - needle_len + 1;
399 for (i = limit; i >= 1; i--)
400 for (j = 0; j < needles.length; j += needle_len)
401 if (!memcmp (&haystack.string[i - 1],
402 &needles.string[j], needle_len))
409 function LENGTH (string s)
414 string function LOWER (string s)
418 for (i = 0; i < s.length; i++)
419 s.string[i] = tolower ((unsigned char) s.string[i]);
423 function MBLEN.BYTE (string s, idx)
425 if (idx < 0 || idx >= s.length || (int) idx != idx)
431 string function UPCASE (string s)
435 for (i = 0; i < s.length; i++)
436 s.string[i] = toupper ((unsigned char) s.string[i]);
440 absorb_miss string function LPAD (string s, n)
443 if (n < 0 || n > 255 || (int) n != n)
445 else if (s.length >= n)
449 struct fixed_string t = alloc_string (e, n);
450 memset (t.string, ' ', n - s.length);
451 memcpy (&t.string[(int) n - s.length], s.string, s.length);
456 absorb_miss string function LPAD (string s, n, string c)
459 if (n < 0 || n > 255 || (int) n != n || c.length != 1)
461 else if (s.length >= n)
465 struct fixed_string t = alloc_string (e, n);
466 memset (t.string, c.string[0], n - s.length);
467 memcpy (&t.string[(int) n - s.length], s.string, s.length);
472 absorb_miss string function RPAD (string s, n)
475 if (n < 0 || n > 255 || (int) n != n)
477 else if (s.length >= n)
481 struct fixed_string t = alloc_string (e, n);
482 memcpy (t.string, s.string, s.length);
483 memset (&t.string[s.length], ' ', n - s.length);
488 absorb_miss string function RPAD (string s, n, string c)
491 if (n < 0 || n > 255 || (int) n != n || c.length != 1)
493 else if (s.length >= n)
497 struct fixed_string t = alloc_string (e, n);
498 memcpy (t.string, s.string, s.length);
499 memset (&t.string[s.length], c.string[0], n - s.length);
504 string function LTRIM (string s)
506 while (s.length > 0 && s.string[0] == ' ')
514 string function LTRIM (string s, string c)
518 while (s.length > 0 && s.string[0] == c.string[0])
529 string function RTRIM (string s)
531 while (s.length > 0 && s.string[s.length - 1] == ' ')
536 string function RTRIM (string s, string c)
540 while (s.length > 0 && s.string[s.length - 1] == c.string[0])
548 function NUMBER (string s, ni_format f)
557 di.e = s.string + min (s.length, di.format.w);
562 absorb_miss string function STRING (x, no_format f)
566 struct fixed_string dst;
569 dst = alloc_string (e, f->w);
570 assert ((formats[f->type].cat & FCAT_STRING) == 0);
571 data_out (dst.string, f, &v);
575 absorb_miss string function SUBSTR (string s, ofs)
578 if (ofs >= 1 && ofs <= s.length && (int) ofs == ofs)
579 return copy_string (e, &s.string[(int) ofs - 1], s.length - ofs + 1);
584 absorb_miss string function SUBSTR (string s, ofs, cnt)
587 if (ofs >= 1 && ofs <= s.length && (int) ofs == ofs
588 && cnt >= 1 && cnt <= INT_MAX && (int) cnt == cnt)
590 int cnt_max = s.length - (int) ofs + 1;
591 return copy_string (e, &s.string[(int) ofs - 1],
592 cnt <= cnt_max ? cnt : cnt_max);
599 operator SQUARE (x) = x * x;
600 boolean operator NUM_TO_BOOLEAN (x)
602 if (x == 0. || x == 1. || x == SYSMIS)
606 msg (SE, _("A number being treated as a Boolean in an "
607 "expression was found to have a value other than "
608 "0 (false), 1 (true), or the system-missing value. "
609 "The result was forced to 0."));
614 operator BOOLEAN_TO_NUM (boolean x) = x;
616 // Beta distribution.
617 function PDF.BETA (x >= 0 && x <= 1, a > 0, b > 0)
618 = gsl_ran_beta_pdf (x, a, b);
619 function CDF.BETA (x >= 0 && x <= 1, a > 0, b > 0) = gsl_cdf_beta_P (x, a, b);
620 function IDF.BETA (P >= 0 && P <= 1, a > 0, b > 0) = idf_beta (P, a, b);
621 no_opt function RV.BETA (a > 0, b > 0) = gsl_ran_beta (get_rng (), a, b);
622 function NCDF.BETA (x >= 0, a > 0, b > 0, lambda > 0)
623 = ncdf_beta (x, a, b, lambda);
624 function NPDF.BETA (x >= 0, a > 0, b > 0, lambda > 0)
625 = npdf_beta (x, a, b, lambda);
627 // Bivariate normal distribution.
628 function CDF.BVNOR (x0, x1, r >= -1 && r <= 1) = cdf_bvnor (x0, x1, r);
629 function PDF.BVNOR (x0, x1, r >= -1 && r <= 1)
630 = gsl_ran_bivariate_gaussian_pdf (x0, x1, 1, 1, r);
632 // Cauchy distribution.
633 function CDF.CAUCHY (x, a, b > 0) = gsl_cdf_cauchy_P ((x - a) / b, 1);
634 function IDF.CAUCHY (P > 0 && P < 1, a, b > 0)
635 = a + b * gsl_cdf_cauchy_Pinv (P, 1);
636 function PDF.CAUCHY (x, a, b > 0) = gsl_ran_cauchy_pdf ((x - a) / b, 1) / b;
637 no_opt function RV.CAUCHY (a, b > 0) = a + b * gsl_ran_cauchy (get_rng (), 1);
639 // Chi-square distribution.
640 function CDF.CHISQ (x >= 0, df > 0) = gsl_cdf_chisq_P (x, df);
641 function IDF.CHISQ (P >= 0 && P < 1, df > 0) = gsl_cdf_chisq_Pinv (P, df);
642 function PDF.CHISQ (x >= 0, df > 0) = gsl_ran_chisq_pdf (x, df);
643 no_opt function RV.CHISQ (df > 0) = gsl_ran_chisq (get_rng (), df);
644 function NCDF.CHISQ (x >= 0, df > 0, c) = unimplemented;
645 function NPDF.CHISQ (x >= 0, df > 0, c) = unimplemented;
646 function SIG.CHISQ (x >= 0, df > 0) = gsl_cdf_chisq_Q (x, df);
648 // Exponential distribution.
649 function CDF.EXP (x >= 0, a > 0) = gsl_cdf_exponential_P (x, 1. / a);
650 function IDF.EXP (P >= 0 && P < 1, a > 0)
651 = gsl_cdf_exponential_Pinv (P, 1. / a);
652 function PDF.EXP (x >= 0, a > 0) = gsl_ran_exponential_pdf (x, 1. / a);
653 no_opt function RV.EXP (a > 0) = gsl_ran_exponential (get_rng (), 1. / a);
655 // Exponential power distribution.
656 extension function PDF.XPOWER (x, a > 0, b >= 0)
657 = gsl_ran_exppow_pdf (x, a, b);
658 no_opt extension function RV.XPOWER (a > 0, b >= 0)
659 = gsl_ran_exppow (get_rng (), a, b);
662 function CDF.F (x >= 0, df1 > 0, df2 > 0) = gsl_cdf_fdist_P (x, df1, df2);
663 function IDF.F (P >= 0 && P < 1, df1 > 0, df2 > 0) = idf_fdist (P, df1, df2);
664 function PDF.F (x >= 0, df1 > 0, df2 > 0) = gsl_ran_fdist_pdf (x, df1, df2);
665 no_opt function RV.F (df1 > 0, df2 > 0) = gsl_ran_fdist (get_rng (), df1, df2);
666 function NCDF.F (x >= 0, df1 > 0, df2 > 0, lambda >= 0) = unimplemented;
667 function NPDF.F (x >= 0, df1 > 0, df2 > 0, lmabda >= 0) = unimplemented;
668 function SIG.F (x >= 0, df1 > 0, df2 > 0) = unimplemented;
670 // Gamma distribution.
671 function CDF.GAMMA (x >= 0, a > 0, b > 0) = gsl_cdf_gamma_P (x, a, 1. / b);
672 function IDF.GAMMA (P >= 0 && P <= 1, a > 0, b > 0)
673 = gsl_cdf_gamma_Pinv (P, a, 1. / b);
674 function PDF.GAMMA (x >= 0, a > 0, b > 0) = gsl_ran_gamma_pdf (x, a, 1. / b);
675 no_opt function RV.GAMMA (a > 0, b > 0)
676 = gsl_ran_gamma (get_rng (), a, 1. / b);
678 // Half-normal distribution.
679 function CDF.HALFNRM (x, a, b > 0) = unimplemented;
680 function IDF.HALFNRM (P > 0 && P < 1, a, b > 0) = unimplemented;
681 function PDF.HALFNRM (x, a, b > 0) = unimplemented;
682 no_opt function RV.HALFNRM (a, b > 0) = unimplemented;
684 // Inverse Gaussian distribution.
685 function CDF.IGAUSS (x > 0, a > 0, b > 0) = unimplemented;
686 function IDF.IGAUSS (P >= 0 && P < 1, a > 0, b > 0) = unimplemented;
687 function PDF.IGAUSS (x > 0, a > 0, b > 0) = unimplemented;
688 no_opt function RV.IGAUSS (a > 0, b > 0) = unimplemented;
690 // Landau distribution.
691 extension function PDF.LANDAU (x) = gsl_ran_landau_pdf (x);
692 no_opt extension function RV.LANDAU () = gsl_ran_landau (get_rng ());
694 // Laplace distribution.
695 function CDF.LAPLACE (x, a, b > 0) = gsl_cdf_laplace_P ((x - a) / b, 1);
696 function IDF.LAPLACE (P > 0 && P < 1, a, b > 0)
697 = a + b * gsl_cdf_laplace_Pinv (P, 1);
698 function PDF.LAPLACE (x, a, b > 0) = gsl_ran_laplace_pdf ((x - a) / b, 1) / b;
699 no_opt function RV.LAPLACE (a, b > 0)
700 = a + b * gsl_ran_laplace (get_rng (), 1);
702 // Levy alpha-stable distribution.
703 no_opt extension function RV.LEVY (c, alpha > 0 && alpha <= 2)
704 = gsl_ran_levy (get_rng (), c, alpha);
706 // Levy skew alpha-stable distribution.
707 no_opt extension function RV.LVSKEW (c, alpha > 0 && alpha <= 2,
708 beta >= -1 && beta <= 1)
709 = gsl_ran_levy_skew (get_rng (), c, alpha, beta);
711 // Logistic distribution.
712 function CDF.LOGISTIC (x, a, b > 0) = gsl_cdf_logistic_P ((x - a) / b, 1);
713 function IDF.LOGISTIC (P > 0 && P < 1, a, b > 0)
714 = a + b * gsl_cdf_logistic_Pinv (P, 1);
715 function PDF.LOGISTIC (x, a, b > 0)
716 = gsl_ran_logistic_pdf ((x - a) / b, 1) / b;
717 no_opt function RV.LOGISTIC (a, b > 0)
718 = a + b * gsl_ran_logistic (get_rng (), 1);
720 // Lognormal distribution.
721 function CDF.LNORMAL (x >= 0, m > 0, s > 0)
722 = gsl_cdf_lognormal_P (x, log (m), s);
723 function IDF.LNORMAL (P >= 0 && P < 1, m > 0, s > 0)
724 = gsl_cdf_lognormal_Pinv (P, log (m), s);
725 function PDF.LNORMAL (x >= 0, m > 0, s > 0)
726 = gsl_ran_lognormal_pdf (x, log (m), s);
727 no_opt function RV.LNORMAL (m > 0, s > 0)
728 = gsl_ran_lognormal (get_rng (), log (m), s);
730 // Normal distribution.
731 function CDF.NORMAL (x, u, s > 0) = gsl_cdf_gaussian_P (x - u, s);
732 function IDF.NORMAL (P > 0 && P < 1, u, s > 0)
733 = u + gsl_cdf_gaussian_Pinv (P, s);
734 function PDF.NORMAL (x, u, s > 0) = gsl_ran_gaussian_pdf ((x - u) / s, 1) / s;
735 no_opt function RV.NORMAL (u, s > 0) = u + gsl_ran_gaussian (get_rng (), s);
736 function CDFNORM (x) = gsl_cdf_ugaussian_P (x);
737 function PROBIT (P > 0 && P < 1) = gsl_cdf_ugaussian_Pinv (P);
738 no_opt function NORMAL (s > 0) = gsl_ran_gaussian (get_rng (), s);
740 // Normal tail distribution.
741 function PDF.NTAIL (x, a > 0, sigma > 0)
742 = gsl_ran_gaussian_tail_pdf (x, a, sigma);
743 no_opt function RV.NTAIL (a > 0, sigma > 0)
744 = gsl_ran_gaussian_tail (get_rng (), a, sigma);
746 // Pareto distribution.
747 function CDF.PARETO (x >= a, a > 0, b > 0) = gsl_cdf_pareto_P (x, b, a);
748 function IDF.PARETO (P >= 0 && P < 1, a > 0, b > 0)
749 = gsl_cdf_pareto_Pinv (P, b, a);
750 function PDF.PARETO (x >= a, a > 0, b > 0) = gsl_ran_pareto_pdf (x, b, a);
751 no_opt function RV.PARETO (a > 0, b > 0) = gsl_ran_pareto (get_rng (), b, a);
753 // Rayleigh distribution.
754 extension function CDF.RAYLEIGH (x, sigma > 0) = gsl_cdf_rayleigh_P (x, sigma);
755 extension function IDF.RAYLEIGH (P >= 0 && P <= 1, sigma > 0)
756 = gsl_cdf_rayleigh_Pinv (P, sigma);
757 extension function PDF.RAYLEIGH (x, sigma > 0)
758 = gsl_ran_rayleigh_pdf (x, sigma);
759 no_opt extension function RV.RAYLEIGH (sigma > 0)
760 = gsl_ran_rayleigh (get_rng (), sigma);
762 // Rayleigh tail distribution.
763 extension function PDF.RTAIL (x, a, sigma)
764 = gsl_ran_rayleigh_tail_pdf (x, a, sigma);
765 no_opt extension function RV.RTAIL (a, sigma)
766 = gsl_ran_rayleigh_tail (get_rng (), a, sigma);
768 // Studentized maximum modulus distribution.
769 function CDF.SMOD (x > 0, a >= 1, b >= 1) = unimplemented;
770 function IDF.SMOD (P >= 0 && P < 1, a >= 1, b >= 1) = unimplemented;
772 // Studentized range distribution.
773 function CDF.SRANGE (x > 0, a >= 1, b >= 1) = unimplemented;
774 function IDF.SRANGE (P >= 0 && P < 1, a >= 1, b >= 1) = unimplemented;
776 // Student t distribution.
777 function CDF.T (x, df > 0) = gsl_cdf_tdist_P (x, df);
778 function IDF.T (P > 0 && P < 1, df > 0) = gsl_cdf_tdist_Pinv (P, df);
779 function PDF.T (x, df > 0) = gsl_ran_tdist_pdf (x, df);
780 no_opt function RV.T (df > 0) = gsl_ran_tdist (get_rng (), df);
781 function NCDF.T (x, df > 0, nc) = unimplemented;
782 function NPDF.T (x, df > 0, nc) = unimplemented;
784 // Type-1 Gumbel distribution.
785 extension function CDF.T1G (x, a, b) = gsl_cdf_gumbel1_P (x, a, b);
786 extension function IDF.T1G (P >= 0 && P <= 1, a, b)
787 = gsl_cdf_gumbel1_P (P, a, b);
788 extension function PDF.T1G (x, a, b) = gsl_ran_gumbel1_pdf (x, a, b);
789 no_opt extension function RV.T1G (a, b) = gsl_ran_gumbel1 (get_rng (), a, b);
791 // Type-2 Gumbel distribution.
792 extension function CDF.T2G (x, a, b) = gsl_cdf_gumbel2_P (x, a, b);
793 extension function IDF.T2G (P >= 0 && P <= 1, a, b)
794 = gsl_cdf_gumbel2_P (P, a, b);
795 extension function PDF.T2G (x, a, b) = gsl_ran_gumbel2_pdf (x, a, b);
796 no_opt extension function RV.T2G (a, b) = gsl_ran_gumbel2 (get_rng (), a, b);
798 // Uniform distribution.
799 function CDF.UNIFORM (x <= b, a <= x, b) = gsl_cdf_flat_P (x, a, b);
800 function IDF.UNIFORM (P >= 0 && P <= 1, a <= b, b)
801 = gsl_cdf_flat_Pinv (P, a, b);
802 function PDF.UNIFORM (x <= b, a <= x, b) = gsl_ran_flat_pdf (x, a, b);
803 no_opt function RV.UNIFORM (a <= b, b) = gsl_ran_flat (get_rng (), a, b);
804 no_opt function UNIFORM (b >= 0) = gsl_ran_flat (get_rng (), 0, b);
806 // Weibull distribution.
807 function CDF.WEIBULL (x >= 0, a > 0, b > 0) = gsl_cdf_weibull_P (x, a, b);
808 function IDF.WEIBULL (P >= 0 && P < 1, a > 0, b > 0)
809 = gsl_cdf_weibull_Pinv (P, a, b);
810 function PDF.WEIBULL (x >= 0, a > 0, b > 0) = gsl_ran_weibull_pdf (x, a, b);
811 no_opt function RV.WEIBULL (a > 0, b > 0) = gsl_ran_weibull (get_rng (), a, b);
813 // Bernoulli distribution.
814 function CDF.BERNOULLI (k == 0 || k == 1, p >= 0 && p <= 1)
816 function PDF.BERNOULLI (k == 0 || k == 1, p >= 0 && p <= 1)
817 = gsl_ran_bernoulli_pdf (k, p);
818 no_opt function RV.BERNOULLI (p >= 0 && p <= 1)
819 = gsl_ran_bernoulli (get_rng (), p);
821 // Binomial distribution.
822 function CDF.BINOM (k, n > 0 && n == floor (n), p >= 0 && p <= 1)
824 function PDF.BINOM (k >= 0 && k == floor (k) && k <= n,
825 n > 0 && n == floor (n),
827 = gsl_ran_binomial_pdf (k, p, n);
828 no_opt function RV.BINOM (p > 0 && p == floor (p), n >= 0 && n <= 1)
829 = gsl_ran_binomial (get_rng (), p, n);
831 // Geometric distribution.
832 function CDF.GEOM (k >= 1 && k == floor (k), p >= 0 && p <= 1) = unimplemented;
833 function PDF.GEOM (k >= 1 && k == floor (k),
835 = gsl_ran_geometric_pdf (k, p);
836 no_opt function RV.GEOM (p >= 0 && p <= 1) = gsl_ran_geometric (get_rng (), p);
838 // Hypergeometric distribution.
839 function CDF.HYPER (k >= 0 && k == floor (k) && k <= c,
840 a > 0 && a == floor (a),
841 b > 0 && b == floor (b) && b <= a,
842 c > 0 && c == floor (c) && c <= a)
844 function PDF.HYPER (k >= 0 && k == floor (k) && k <= c,
845 a > 0 && a == floor (a),
846 b > 0 && b == floor (b) && b <= a,
847 c > 0 && c == floor (c) && c <= a)
848 = gsl_ran_hypergeometric_pdf (k, c, a - c, b);
849 no_opt function RV.HYPER (a > 0 && a == floor (a),
850 b > 0 && b == floor (b) && b <= a,
851 c > 0 && c == floor (c) && c <= a)
852 = gsl_ran_hypergeometric (get_rng (), c, a - c, b);
854 // Logarithmic distribution.
855 extension function PDF.LOG (k >= 1, p > 0 && p <= 1)
856 = gsl_ran_logarithmic_pdf (k, p);
857 no_opt extension function RV.LOG (p > 0 && p <= 1)
858 = gsl_ran_logarithmic (get_rng (), p);
860 // Negative binomial distribution.
861 function CDF.NEGBIN (k >= 1, n == floor (n), p > 0 && p <= 1) = unimplemented;
862 function PDF.NEGBIN (k >= 1, n == floor (n), p > 0 && p <= 1)
863 = gsl_ran_negative_binomial_pdf (k, p, n);
864 no_opt function RV.NEGBIN (n == floor (n), p > 0 && p <= 1)
865 = gsl_ran_negative_binomial (get_rng (), p, n);
867 // Poisson distribution.
868 function CDF.POISSON (k >= 0 && k == floor (k), mu > 0) = unimplemented;
869 function PDF.POISSON (k >= 0 && k == floor (k), mu > 0)
870 = gsl_ran_poisson_pdf (k, mu);
871 no_opt function RV.POISSON (mu > 0) = gsl_ran_poisson (get_rng (), mu);
874 absorb_miss boolean function MISSING (x) = x == SYSMIS || !finite (x);
875 absorb_miss boolean function SYSMIS (x) = x == SYSMIS || !finite (x);
876 no_opt boolean function SYSMIS (num_var v)
879 return case_num (c, v->fv) == SYSMIS;
881 no_opt boolean function VALUE (num_var v)
884 return case_num (c, v->fv);
887 no_opt operator VEC_ELEM_NUM (idx)
891 if (idx >= 1 && idx <= v->cnt)
893 const struct variable *var = v->var[(int) idx - 1];
894 double value = case_num (c, var->fv);
895 return !is_num_user_missing (value, var) ? value : SYSMIS;
900 msg (SE, _("SYSMIS is not a valid index value for vector "
901 "%s. The result will be set to SYSMIS."),
904 msg (SE, _("%g is not a valid index value for vector %s. "
905 "The result will be set to SYSMIS."),
911 absorb_miss no_opt string operator VEC_ELEM_STR (idx)
916 if (idx >= 1 && idx <= v->cnt)
918 struct variable *var = v->var[(int) idx - 1];
919 return copy_string (e, case_str (c, var->fv), var->width);
924 msg (SE, _("SYSMIS is not a valid index value for vector "
925 "%s. The result will be set to the empty string."),
928 msg (SE, _("%g is not a valid index value for vector %s. "
929 "The result will be set to the empty string."),
937 no_opt operator NUM_VAR ()
941 double d = case_num (c, v->fv);
942 return !is_num_user_missing (d, v) ? d : SYSMIS;
945 no_opt string operator STR_VAR ()
950 struct fixed_string s = alloc_string (e, v->width);
951 memcpy (s.string, case_str (c, v->fv), v->width);
955 no_opt function LAG (num_var v, pos_int n_before)
957 struct ccase *c = lagged_case (n_before);
960 double x = case_num (c, v->fv);
961 return !is_num_user_missing (x, v) ? x : SYSMIS;
967 no_opt function LAG (num_var v)
969 struct ccase *c = lagged_case (1);
972 double x = case_num (c, v->fv);
973 return !is_num_user_missing (x, v) ? x : SYSMIS;
979 no_opt string function LAG (str_var v, pos_int n_before)
982 struct ccase *c = lagged_case (n_before);
984 return copy_string (e, case_str (c, v->fv), v->width);
989 no_opt string function LAG (str_var v)
992 struct ccase *c = lagged_case (1);
994 return copy_string (e, case_str (c, v->fv), v->width);
999 no_opt operator NUM_SYS ()
1003 return case_num (c, v->fv) == SYSMIS;
1006 no_opt operator NUM_VAL ()
1010 return case_num (c, v->fv);
1013 no_opt operator CASENUM ()