expressions: Implement the MEDIAN function.
[pspp] / src / language / expressions / operations.def
index 60ed2eac2022b863af4ef05dbf34f22452687aa5..18ab4447c824032a7f896161c9fc760fa31a2d62 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c -*-
 //
 // PSPP - a program for statistical analysis.
-// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012, 2015 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012, 2015, 2016 Free Software Foundation, Inc.
 // 
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -168,6 +168,11 @@ function MEAN.1 (a[n])
   return mean;
 }
 
+function MEDIAN.1 (a[n])
+{
+  return median (a, n);
+}
+
 function MIN.1 (a[n])
 {
   double min;
@@ -399,7 +404,6 @@ function INDEX (string haystack, string needles, needle_len_d)
     }
 }
 
-
 function RINDEX (string haystack, string needle)
 {
   if (needle.length == 0)
@@ -417,7 +421,7 @@ function RINDEX (string haystack, string needle)
 
 function RINDEX (string haystack, string needles, needle_len_d)
 {
-  if (needle_len_d <= INT_MIN || needle_len_d >= INT_MAX
+  if (needle_len_d <= 0 || needle_len_d >= INT_MAX
       || (int) needle_len_d != needle_len_d
       || needles.length == 0)
     return SYSMIS;
@@ -504,6 +508,15 @@ absorb_miss string function LPAD (string s, n, string c)
     }
 }
 
+string function REPLACE (string haystack, string needle, string replacement)
+    expression e;
+  = replace_string (e, haystack, needle, replacement, DBL_MAX);
+
+absorb_miss string function REPLACE (string haystack, string needle,
+                                     string replacement, n)
+    expression e;
+  = replace_string (e, haystack, needle, replacement, n);
+
 absorb_miss string function RPAD (string s, n)
      expression e;
 {