Function: math[slice] - cuts floats after the n-th fractional digit

Calling Sequence:

slice(expr, n);
slice(expr, n, 'adjust');

Parameters:

expr - any algebraic expression
n - an integer
'adjust' - (optional) the name (accuracy option)

Description:

If n > 0, then math/slice cuts all floats in an expression after the n-th fractional digit. Numeric values that are not of type float are left unchanged in this case.

If n = 0 (in this case the second argument may be omitted), then math/slice rounds all floats in an expression to the nearest integer towards 0. This is equivalent to the trunc function. Here, integers and fractions are ignored, as well.

If n < 0, math/slice replaces the first |n| digits of integers, fractions (internally converted to floats), and floats v in the expression expr from the right of trunc(v) with zeros.

Note that in the first form, the accuracy of the result in general is dependent on the setting of Digits.

In the second form, if the option 'adjust' is passed as the third argument to slice and if a float v in expr is of type float, the value of Digits is set to length(op(1, v)) so that there are no rounding errors.

This function is part of the math package, and so can be used only after performing the command with(math) or with(math, slice).

Examples:

> with(math, slice):

> pi := 3.141592654:

> slice(pi, 6);

[Maple Math]

> slice(pi, 0);

[Maple Math]

> i := 1234:

> slice(i, 2);

[Maple Math]

> slice(i, -2);

[Maple Math]

> ir := evalf(exp(1), 30);

[Maple Math]

> slice(ir, 3);

[Maple Math]

> slice(ir, 15);

[Maple Math]

> slice(ir, 15, adjust);

[Maple Math]

> slice(31.45, -1);

[Maple Math]

See Also:

math/roundf , math/cutzeros , math/cancel ,
Digits , trunc , frac , round , information on the internal representation of Maple floats.

Version History:

Version 1.0 - April 18, 1998

Version 1.0 - June 09, 1998