Talk about implied decimal places in FORTRAN style for DATA LIST
[pspp-builds.git] / src / expr-evl.c
index 3c7433753197d08caf4a7801da771409cbfa1cb7..d3e02ea1dcbcf6d78270c15ca2fface7a15511ea 100644 (file)
 #include "expr.h"
 #include "exprP.h"
 #include "error.h"
+#include <gsl/gsl_randist.h>
 #include <math.h>
 #include <errno.h>
 #include <stdio.h>
+#include "case.h"
 #include "data-in.h"
+#include "dictionary.h"
 #include "error.h"
 #include "julcal/julcal.h"
 #include "magic.h"
 #include "misc.h"
 #include "moments.h"
 #include "pool.h"
-#include "random.h"
+#include "settings.h"
 #include "str.h"
 #include "var.h"
 #include "vfm.h"
 #include "vfmP.h"
 
 double
-expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
+expr_evaluate (const struct expression *e, const struct ccase *c, int case_idx,
                union value *v)
 {
   unsigned char *op = e->op;
@@ -731,7 +734,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
          break;
        case OP_XDATE_JDAY:
          if (sp->f != SYSMIS)
-           sp->f = 86400. * julian_to_jday (sp->f / 86400.);
+           sp->f = julian_to_jday (sp->f / 86400.);
          break;
        case OP_XDATE_MDAY:
          if (sp->f != SYSMIS)
@@ -1120,11 +1123,11 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
          break;
        case OP_NORMAL:
          if (sp->f != SYSMIS)
-           sp->f *= rng_get_double_normal (pspp_rng ());
+           sp->f = gsl_ran_gaussian (get_rng (), sp->f);
          break;
        case OP_UNIFORM:
          if (sp->f != SYSMIS)
-           sp->f *= rng_get_double (pspp_rng ());
+           sp->f *= gsl_rng_uniform (get_rng ());
          break;
        case OP_SYSMIS:
          sp->f = sp->f == SYSMIS || !finite (sp->f);
@@ -1148,7 +1151,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
                break;
              }
             assert (c != NULL);
-           sp->f = c->data[v->var[rindx - 1]->fv].f;
+           sp->f = case_num (c, v->var[rindx - 1]->fv);
          }
          break;
        case OP_VEC_ELEM_STR:
@@ -1177,7 +1180,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
            sp->c = pool_alloc (e->pool, v->width + 1);
            sp->c[0] = v->width;
             assert (c != NULL);
-           memcpy (&sp->c[1], c->data[v->fv].s, v->width);
+           memcpy (&sp->c[1], case_str (c, v->fv), v->width);
          }
          break;
 
@@ -1195,7 +1198,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
        case OP_NUM_VAR:
          sp++;
           assert (c != NULL);
-         sp->f = c->data[(*vars)->fv].f;
+         sp->f = case_num (c, (*vars)->fv);
          if (is_num_user_missing (sp->f, *vars))
            sp->f = SYSMIS;
          vars++;
@@ -1208,7 +1211,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
            sp->c = pool_alloc (e->pool, width + 1);
            sp->c[0] = width;
             assert (c != NULL);
-           memcpy (&sp->c[1], &c->data[(*vars)->fv], width);
+           memcpy (&sp->c[1], case_str (c, (*vars)->fv), width);
            vars++;
          }
          break;
@@ -1221,7 +1224,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
              sp->f = SYSMIS;
            else
              {
-               sp->f = c->data[(*vars)->fv].f;
+               sp->f = case_num (c, (*vars)->fv);
                if (is_num_user_missing (sp->f, *vars))
                  sp->f = SYSMIS;
              }
@@ -1240,7 +1243,7 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
            if (c == NULL)
              memset (sp->c, ' ', width);
            else
-             memcpy (&sp->c[1], &c->data[(*vars)->fv], width);
+             memcpy (&sp->c[1], case_str (c, (*vars)->fv), width);
            
            vars++;
          }
@@ -1248,16 +1251,16 @@ expr_evaluate (const struct expression *e, const struct ccase *c, int case_num,
        case OP_NUM_SYS:
          sp++;
           assert (c != NULL);
-         sp->f = c->data[*op++].f == SYSMIS;
+         sp->f = case_num (c, *op++) == SYSMIS;
          break;
        case OP_NUM_VAL:
          sp++;
           assert (c != NULL);
-         sp->f = c->data[*op++].f;
+         sp->f = case_num (c, *op++);
          break;
        case OP_CASENUM:
          sp++;
-         sp->f = case_num;
+         sp->f = case_idx;
          break;
 
        case OP_SENTINEL: