Requested by Tom Smekens.
* The GRAPH command is now available. Initially it supports
scatterplots and histograms.
+ * The RND operator in expressions now supports additional operands
+ for rounding to values other than integers and to indicate a level
+ of rounding fuzz. The default rounding fuzz may now be controlled
+ and displayed with SET FUZZBITS and SHOW FUZZBITS, respectively.
+
Changes from 0.8.3 to 0.8.4:
* Formatting of SYSFILE INFO output was made easier to read.
@end deftypefn
@cindex rounding
-@deftypefn {Function} {} RND (@var{number})
-Takes the absolute value of @var{number} and rounds it to an integer.
-Then, if @var{number} was negative originally, negates the result.
+@deftypefn {Function} {} RND (@var{number} [, @var{mult}[, @var{fuzzbits}]])
+Rounds @var{number} and rounds it to a multiple of @var{mult} (by
+default 1). Halves are rounded away from zero, as are values that
+fall short of halves by less than @var{fuzzbits} of errors in the
+least-significant bits of @var{number}. If @var{fuzzbits} is not
+specified then the default is taken from SET FUZZBITS (@pxref{SET
+FUZZBITS}), which is 6 unless overridden.
@end deftypefn
@cindex truncation
/MXLOOPS=@var{max_loops}
/SEED=@{RANDOM,@var{seed_value}@}
/UNDEFINED=@{WARN,NOWARN@}
+ /FUZZBITS=@var{fuzzbits}
(data output)
/CC@{A,B,C,D,E@}=@{'@var{npre},@var{pre},@var{suf},@var{nsuf}','@var{npre}.@var{pre}.@var{suf}.@var{nsuf}'@}
@item UNDEFINED
Currently not used.
+@item FUZZBITS
+@anchor{SET FUZZBITS}
+The maximum number of bits of errors in the least-significant places
+to accept for rounding up a value that is almost halfway between two
+possibilities for rounding with the RND operator (@pxref{Miscellaneous
+Mathematics}). The default @var{fuzzbits} is 6.
+
@item WORKSPACE
The maximum amount of memory (in kilobytes) that @pspp{} will use to store data being processed.
If memory in excess of the workspace size is required, then @pspp{} will start
[DIRECTORY]
[ENVIRONMENT]
[FORMAT]
+ [FUZZBITS]
[LENGTH]
[MXERRS]
[MXLOOPS]
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2015 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
size_t workspace;
struct fmt_spec default_format;
bool testing_mode;
+ int fuzzbits;
int cmd_algorithm;
int global_algorithm;
64L * 1024 * 1024, /* workspace */
{FMT_F, 8, 2}, /* default_format */
false, /* testing_mode */
+ 6, /* fuzzbits */
ENHANCED, /* cmd_algorithm */
ENHANCED, /* global_algorithm */
ENHANCED, /* syntax */
the_settings.testing_mode = testing_mode;
}
+int
+settings_get_fuzzbits (void)
+{
+ return the_settings.fuzzbits;
+}
+
+void
+settings_set_fuzzbits (int fuzzbits)
+{
+ the_settings.fuzzbits = fuzzbits;
+}
+
/* Return the current algorithm setting */
enum behavior_mode
settings_get_algorithm (void)
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2015 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
bool settings_get_testing_mode (void);
void settings_set_testing_mode (bool);
+int settings_get_fuzzbits (void);
+void settings_set_fuzzbits (int);
+
enum settings_var_style
{
SETTINGS_VAR_STYLE_NAMES,
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2010, 2011, 2015 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
return sum;
}
}
+
+double
+round_nearest (double x, double mult, double fuzzbits)
+{
+ double adjustment;
+
+ if (fuzzbits <= 0)
+ fuzzbits = settings_get_fuzzbits ();
+ adjustment = .5 + exp2 (fuzzbits - DBL_MANT_DIG);
+
+ x /= mult;
+ x = x >= 0. ? floor (x + adjustment) : -floor (-x + adjustment);
+ return x * mult;
+}
double idf_fdist (double P, double a, double b);
+double round_nearest (double x, double mult, double fuzzbits);
+
#endif /* expressions/helpers.h */
// -*- c -*-
//
// PSPP - a program for statistical analysis.
-// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012, 2015 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
function LN (x) = check_errno (log (x));
function LNGAMMA (x >= 0) = gsl_sf_lngamma (x);
function MOD10 (x) = fmod (x, 10);
-function RND (x) = x >= 0. ? floor (x + .5) : -floor (-x + .5);
+function RND (x) = round_nearest (x, 1, 0);
+function RND (x, mult != 0) = round_nearest (x, mult, 0);
+function RND (x, mult != 0, fuzzbits >= 0) = round_nearest (x, mult, fuzzbits);
function SIN (x) = sin (x);
function SQRT (x >= 0) = sqrt (x);
function TAN (x) = check_errno (tan (x));
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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
epoch=custom;
errors=custom;
format=custom;
+ fuzzbits=integer;
headers=headers:no/yes/blank;
highres=hires:on/off;
histogram=string;
if (cmd.sbc_decimal)
settings_set_decimal_char (cmd.dec == STC_DOT ? '.' : ',');
+ if (cmd.sbc_fuzzbits)
+ {
+ int fuzzbits = cmd.n_fuzzbits[0];
+ if (fuzzbits >= 0 && fuzzbits <= 20)
+ settings_set_fuzzbits (fuzzbits);
+ else
+ msg (SE, _("%s must be between 0 and 20."), "FUZZBITS");
+ }
if (cmd.sbc_include)
settings_set_include (cmd.inc == STC_ON);
return xstrdup (fmt_to_string (settings_get_format (), str));
}
+static char *
+show_fuzzbits (const struct dataset *ds UNUSED)
+{
+ return xasprintf ("%d", settings_get_fuzzbits ());
+}
+
static char *
show_journal (const struct dataset *ds UNUSED)
{
{"ENVIRONMENT", show_system},
{"ERRORS", show_errors},
{"FORMAT", show_format},
+ {"FUZZBITS", show_fuzzbits},
{"JOURNAL", show_journal},
{"LENGTH", show_length},
{"LOCALE", show_locale},
[[rnd(5.6)], [6.00]],
[[rnd(-5.4)], [-5.00]],
[[rnd(-5.6)], [-6.00]],
+ [[rnd(5.56, .1)], [5.60]],
+ [[rnd(-5.56, .1)], [-5.60]],
+ [[rnd(.5)], [1.00]],
+ [[rnd(.5 - 2**-53)], [1.00]],
+ [[rnd(.5 - 2**-52)], [1.00]],
+ [[rnd(.5 - 2**-51)], [1.00]],
+ [[rnd(.5 - 2**-45)], [0.00]],
+ [[rnd(.5 - 2**-45, 1, 10)], [1.00]],
[[rnd('x')], [error],
- [error: DEBUG EVALUATE: Type mismatch invoking RND(number) as rnd(string).]],
+ [error: DEBUG EVALUATE: Function invocation rnd(string) does not match any known function. Candidates are:
+RND(number)
+RND(number, number)
+RND(number, number, number).]],
[[trunc(1.2)], [1.00]],
[[trunc(1.9)], [1.00]],