Pref::outputDigits

Set the number of digits in floating-point outputs

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

Pref::outputDigits(n)
Pref::outputDigits(<UseDigits>)
Pref::outputDigits(<InternalPrecision>)
Pref::outputDigits()

Description

Pref::outputDigits(n) sets the number of digits in outputs of floating-point numbers to an integer n. This command does not set the precision for calculations. See Example 1.

Pref::outputDigits(InternalPrecision) sets the number of digits in floating-point outputs to settings MuPAD® used when creating these floating-point numbers. If you use Pref::outputDigits(InternalPrecision), the lengths of floating-point numbers in the same output region can differ because the numbers were created with different precision. See Example 2.

Pref::outputDigits(UseDigits) restores the setting to the number of digits previously set by DIGITS. The default value for DIGITS is 10. Suppose, you use internal precision for displaying numbers or explicitly specify a number of digits in outputs. If you want to switch back to the number of digits specified by DIGITS, use Pref::outputDigits(UseDigits). See Example 3.

Pref::outputDigits() returns the current setting for the number of digits in outputs of floating-point numbers. This command does not change the setting.

Examples

Example 1

Display the floating-point approximation of using 40 digits without changing the precision for calculations. The default number of digits that MuPAD uses for calculations with floating-point numbers is 10. MuPAD can increase the precision of calculations by several digits (guard digits). Round-off errors cause the last digits in the following result to be incorrect:

Pref::outputDigits(40):
float(1/3)

    Note:   Always explicitly set the precision you need. Do not rely on having guard digits.

To set the precision for calculations with floating-point numbers, use DIGITS. Display the floating-point approximation of using 40 and 15 digits:

DIGITS := 40:
float(1/3);
Pref::outputDigits(15):
float(1/3)

Example 2

Approximate the ratio with different precisions:

DIGITS := 15:
x := float(1/6):
DIGITS := 3:
y := float(1/6):
DIGITS := 40:
z := float(1/6):

Display the floating-point approximation of using the number of digits that MuPAD uses internally. The lengths of floating-point numbers in the same output region can differ because the numbers were created with different precision:

Pref::outputDigits(InternalPrecision):
x;
y;
z

Example 3

To switch back to the number of digits set previously by DIGITS, use Pref::outputDigits(UseDigits):

Pref::outputDigits(UseDigits):
x;
y;
z

Parameters

n

An integer

Return Values

Previously set value

See Also

MuPAD Functions

Was this topic helpful?