- MEDIAN, to compute the median of its arguments.
+ - The TRUNC function in expressions now supports additional arguments
+ for truncating 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.
+
* Bug fixes, including the following notable ones:
- The correlation coefficient in the paired samples t-test
@end deftypefn
@cindex truncation
-@deftypefn {Function} {} TRUNC (@var{number})
-Discards the fractional part of @var{number}; that is, rounds
-@var{number} towards zero.
+@deftypefn {Function} {} TRUNC (@var{number} [, @var{mult}[, @var{fuzzbits}]])
+Rounds @var{number} to a multiple of @var{mult}, toward zero. For the
+default @var{mult} of 1, this is equivalent to discarding the
+fractional part of @var{number}. Values that fall short of a multiple
+of @var{mult} by less than @var{fuzzbits} of errors in the
+least-significant bits of @var{number} are rounded away from zero. If
+@var{fuzzbits} is not specified then the default is taken from SET
+FUZZBITS (@pxref{SET FUZZBITS}), which is 6 unless overridden.
@end deftypefn
@node Trigonometry
}
double
-round_nearest (double x, double mult, double fuzzbits)
+round__ (double x, double mult, double fuzzbits, double adjustment)
{
- double adjustment;
-
if (fuzzbits <= 0)
fuzzbits = settings_get_fuzzbits ();
- adjustment = .5 + exp2 (fuzzbits - DBL_MANT_DIG);
+ adjustment += exp2 (fuzzbits - DBL_MANT_DIG);
x /= mult;
x = x >= 0. ? floor (x + adjustment) : -floor (-x + adjustment);
return x * mult;
}
+double
+round_nearest (double x, double mult, double fuzzbits)
+{
+ return round__ (x, mult, fuzzbits, .5);
+}
+
+double
+round_zero (double x, double mult, double fuzzbits)
+{
+ return round__ (x, mult, fuzzbits, 0);
+}
+
struct substring
replace_string (struct expression *e,
struct substring haystack,
double idf_fdist (double P, double a, double b);
double round_nearest (double x, double mult, double fuzzbits);
+double round_zero (double x, double mult, double fuzzbits);
struct substring replace_string (struct expression *,
struct substring haystack,
function SIN (x) = sin (x);
function SQRT (x >= 0) = sqrt (x);
function TAN (x) = check_errno (tan (x));
-function TRUNC (x) = x >= 0. ? floor (x) : -floor (-x);
+function TRUNC (x) = round_zero (x, 1, 0);
+function TRUNC (x, mult != 0) = round_zero (x, mult, 0);
+function TRUNC (x, mult != 0, fuzzbits >= 0) = round_zero (x, mult, fuzzbits);
absorb_miss function MOD (n, d)
{
[[trunc(1.9)], [1.00]],
[[trunc(-1.2)], [-1.00]],
[[trunc(-1.9)], [-1.00]],
+ [[trunc(5.06, .1)], [5.00]],
+ [[trunc(-5.06, .1)], [-5.00]],
+ [[trunc(1)], [1.00]],
+ [[trunc(1 - 2**-53)], [1.00]],
+ [[trunc(1 - 2**-52)], [1.00]],
+ [[trunc(1 - 2**-51)], [1.00]],
+ [[trunc(1 - 2**-45)], [0.00]],
+ [[trunc(1 - 2**-45, 1, 10)], [1.00]],
[[trunc('x')], [error],
- [error: DEBUG EVALUATE: Type mismatch invoking TRUNC(number) as trunc(string).]])
+ [error: DEBUG EVALUATE: Function invocation trunc(string) does not match any known function. Candidates are:
+TRUNC(number)
+TRUNC(number, number)
+TRUNC(number, number, number).]])
CHECK_EXPR_EVAL([acos arsin artan cos sin tan],
[[acos(.5) / 3.14159 * 180], [60.00]],