trunc
Rounding towards zero
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
trunc(x
)
trunc
rounds a number to the next integer
in the direction of 0
.
For complex arguments, trunc
rounds the real
and the imaginary parts separately.
For real numbers and exact expressions representing real numbers, trunc
returns
integers.
For arguments that contain symbolic identifiers, trunc
returns
unevaluated function calls.
For floatingpoint intervals, trunc
returns
floatingpoint intervals containing all the results of applying trunc
to
the real or complex numbers inside the interval.
If x
is a floatingpoint number, then trunc(x)
truncates
the digits after the decimal point. Thus, trunc
coincides
with floor
for real positive arguments and with ceil
for
real negative arguments.
If the argument is a floatingpoint number of absolute value larger than 10^{DIGITS}, the resulting integer is affected by internal nonsignificant digits. See Example 2.
Internally, exact numerical expressions that are neither integers
nor rational numbers are approximated by floatingpoint numbers before
rounding. Thus, the resulting integer depends on the current DIGITS
setting.
See Example 3.
The functions are sensitive to the environment variable DIGITS
which
determines the numerical working precision.
Round the following real and complex numbers:
trunc(3.5), trunc(7/2), trunc(I/2)
Round the following symbolic expression representing a number:
trunc(PI*I + 7*sin(exp(2)))
Rounding of expressions with symbolic identifiers produces unevaluated function calls:
trunc(x^2 + 3)
Rounding floatingpoint numbers of large absolute value is affected by internal nonsignificant digits:
x := 10^30/3.0
Note that only the first 10 decimal digits are “significant”. Further digits are subject to roundoff effects caused by the internal binary representation. These “insignificant” digits are part of the integer produced by rounding:
trunc(x)
delete x:
Exact numerical expressions are internally converted to floatingpoint
numbers before rounding. Consequently, the current setting of DIGITS
can
affect the result:
x := 10^30  exp(30)^ln(10)
Note that the exact value of this number is 0. Floatingpoint evaluation is subject to severe cancellations:
DIGITS := 10: float(x), trunc(x)
The floatingpoint result is more accurate when a higher precision is used. The rounded values change accordingly:
DIGITS := 20: float(x), trunc(x)
DIGITS := 30: float(x), trunc(x)
delete x, DIGITS:
On floatingpoint intervals, trunc
behaves
as follows:
round(3.5...6.7)
This interval contains the results of trnc(x)
for
all .
Because there are finite numbers represented as RD_INF
and RD_NINF
,
respectively, trunc
returns very small or large
representable numbers in certain cases:
ceil(RD_NINF...RD_NINF)

Arithmetical expression.
x