round

Use only in the MuPAD Notebook Interface.

Syntax

round(x, <n>)

Description

round rounds a number to the nearest integer.

For complex arguments, rounding is applied separately to the
real and the imaginary parts.

For the call round(x, n), the result is a
floating-point number with the n-th decimal digit
after the decimal point being rounded. All further digits are set
to zero. If the integer n is negative, the corresponding
digit to the left of the decimal point is rounded. Cf. Example 2.

Unevaluated function calls are returned for arguments that contain
symbolic identifiers.

For floating-point intervals,
the result will be a floating-point interval containing all the results
of applying the rounding function to the real or complex numbers inside
the interval.

Note:
If the argument is a floating-point number of absolute value
larger than 10DIGITS,
the resulting integer is affected by internal non-significant digits!
Cf. Example 3.

Example 3

Care should be taken when rounding floating-point numbers of
large absolute value:

x := 10^30/3.0

Note that only the first 10 decimal
digits are "significant". Further digits are subject
to round-off effects caused by the internal binary representation.
These "insignificant" digits are part of the integer
produced by rounding:

floor(x), ceil(x)

delete x:

Example 4

Exact numerical expressions are internally converted to floating
point numbers before rounding. Consequently, the present setting of DIGITS can
affect the result:

x := 10^30 - exp(30)^ln(10)

Note that the exact value of this number is 0.
Floating point evaluation is subject to severe cancellations:

DIGITS := 10: float(x), floor(x), ceil(x)

The floating-point result is more accurate when a higher precision
is used. The rounded values change accordingly:

DIGITS := 20: float(x), floor(x), ceil(x)

DIGITS := 30: float(x), floor(x), ceil(x)

delete x, DIGITS:

Example 5

On floating-point intervals, ceil and floor behave
as expected:

ceil(3.5...6.7); floor(3.5...6.7)

These intervals, as easily seen, contain the results of ceil(x) and floor(x) for
all ,
respectively.

Because there are finite numbers represented as RD_INF and RD_NINF,
respectively, ceil and floor return
very small or large representable numbers in certain cases: