Remove "Written by Ben Pfaff <blp@gnu.org>" lines everywhere.
[pspp-builds.git] / src / data / data-out.c
index 6622c7d4fe8fe05a31f1df5cd93d294395c6de87..38f50fafbd0ed6007058c7d722b67d95de6a0d1a 100644 (file)
@@ -1,6 +1,5 @@
 /* PSPP - computes sample statistics.
    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
-   Written by Ben Pfaff <blp@gnu.org>.
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
 #include <stdint.h>
 #include <stdlib.h>
 #include <time.h>
+#include <gsl/gsl_math.h>
 
 #include "calendar.h"
 #include "format.h"
 #include "settings.h"
-#include "variable.h"
+#include "value.h"
 
 #include <libpspp/assertion.h>
 #include <libpspp/float-format.h>
@@ -153,7 +153,7 @@ output_number (const union value *input, const struct fmt_spec *format,
 
   if (number == SYSMIS)
     output_missing (format, output);
-  else if (!isfinite (number))
+  else if (!gsl_finite (number))
     output_infinite (number, format, output);
   else 
     {
@@ -314,7 +314,6 @@ output_date (const union value *input, const struct fmt_spec *format,
              char *output)
 {
   double number = input->f;
-  double magnitude = fabs (number);
   int year, month, day, yday;
 
   const char *template = fmt_date_template (format->type);
@@ -334,6 +333,7 @@ output_date (const union value *input, const struct fmt_spec *format,
         goto missing;
       calendar_offset_to_gregorian (number / 60. / 60. / 24.,
                                     &year, &month, &day, &yday);
+      number = fmod (number, 60. * 60. * 24.);
     }
   else
     year = month = day = yday = 0;
@@ -392,33 +392,33 @@ output_date (const union value *input, const struct fmt_spec *format,
           p += sprintf (p, "%2d", (yday - 1) / 7 + 1);
           break;
         case 'D':
-          if (number < 0)
+          if (number < 0) 
             *p++ = '-';
-          p += sprintf (p, "%.0f", floor (magnitude / 60. / 60. / 24.));
+          number = fabs (number); 
+          p += sprintf (p, "%*.0f", count, floor (number / 60. / 60. / 24.));
+          number = fmod (number, 60. * 60. * 24.);
           break;
-        case 'h':
+        case 'H':
           if (number < 0)
             *p++ = '-';
-          p += sprintf (p, "%.0f", floor (magnitude / 60. / 60.));
-          break;
-        case 'H':
-          p += sprintf (p, "%02d",
-                        (int) fmod (floor (magnitude / 60. / 60.), 24.));
+          number = fabs (number); 
+          p += sprintf (p, "%0*.0f", count, floor (number / 60. / 60.));
+          number = fmod (number, 60. * 60.);
           break;
         case 'M':
-          p += sprintf (p, "%02d",
-                        (int) fmod (floor (magnitude / 60.), 60.));
+          p += sprintf (p, "%02d", (int) floor (number / 60.));
+          number = fmod (number, 60.);
           excess_width = format->w - (p - tmp);
           if (excess_width < 0) 
             goto overflow;
           if (excess_width == 3 || excess_width == 4
               || (excess_width >= 5 && format->d == 0))
-            p += sprintf (p, ":%02d", (int) fmod (magnitude, 60.));
+            p += sprintf (p, ":%02d", (int) number);
           else if (excess_width >= 5)
             {
               int d = MIN (format->d, excess_width - 4);
               int w = d + 3;
-              sprintf (p, ":%0*.*f", w, d, fmod (magnitude, 60.));
+              sprintf (p, ":%0*.*f", w, d, number);
               if (fmt_decimal_char (FMT_F) != '.') 
                 {
                   char *cp = strchr (p, '.');
@@ -428,6 +428,9 @@ output_date (const union value *input, const struct fmt_spec *format,
               p += strlen (p);
             }
           break;
+        case 'X':
+          *p++ = ' ';
+          break;
         default:
           assert (count == 1);
           *p++ = ch;
@@ -658,9 +661,7 @@ output_scientific (double number, const struct fmt_spec *format,
      decimal point without any digits following; that's what the
      # flag does in the call to sprintf, below.) */
   fraction_width = MIN (MIN (format->d + 1, format->w - width), 16);
-  if (format->type != FMT_E
-      && (fraction_width == 1
-          || format->w - width + (style->grouping == 0 && number < 0) <= 2))
+  if (format->type != FMT_E && fraction_width == 1)
     fraction_width = 0; 
   width += fraction_width;
 
@@ -707,8 +708,8 @@ output_scientific (double number, const struct fmt_spec *format,
     p = mempset (p, ' ', ss_length (style->neg_suffix));
 
   assert (p == buf + format->w);
+  memcpy (output, buf, format->w);
 
-  buf_copy_str_lpad (output, format->w, buf);
   return true;
 }
 \f
@@ -950,7 +951,7 @@ power256 (int x)
 static void
 output_infinite (double number, const struct fmt_spec *format, char *output)
 {
-  assert (!isfinite (number));
+  assert (!gsl_finite (number));
   
   if (format->w >= 3)
     {