RunMat
GitHub

format — Set numeric display format for console output in MATLAB and RunMat.

format controls how numeric values are displayed in console output for the current session. Precision modes such as short, long, shortE, longE, shortG, longG, rat, and hex follow MATLAB behavior. Calling format with no arguments resets to short.

Syntax

format()
format(mode)

Inputs

NameTypeRequiredDefaultDescription
modeStringScalarYesFormat mode keyword (short, long, shortE, longE, shortG, longG, rat, hex, compact, loose).

Returns

NameTypeDescription
ansNumericArrayEmpty matrix placeholder returned by sink invocation.

Errors

IdentifierWhenMessage
Input arguments do not match supported format call forms.format: invalid argument configuration
Mode string is not a supported numeric display mode keyword.format: unknown format mode

How format works

  • Calling format with no arguments resets to the default short mode.
  • format short displays 4 decimal places in fixed notation for values in [0.001, 10000); uses scientific notation outside that range.
  • format long displays 15 decimal places in fixed notation for values in [0.001, 10000); uses 14-decimal scientific notation outside that range.
  • format shortE always uses scientific notation with 4 decimal places (e.g., 3.1416e+00).
  • format longE always uses scientific notation with 14 decimal places.
  • format shortG uses the more compact of fixed/scientific notation with 5 significant digits, trimming trailing zeros.
  • format longG uses the more compact of fixed/scientific notation with 15 significant digits, trimming trailing zeros.
  • format rat approximates values as ratios of small integers using a tolerance of 5×10⁻⁷ (e.g., 355/113 for pi). format rational is accepted as an alias.
  • format hex displays the IEEE 754 double-precision hexadecimal bit pattern (e.g., 400921fb54442d18 for pi).
  • format compact and format loose are accepted without error for script compatibility but do not yet change output spacing.
  • The format setting applies to auto-print results and disp output. fprintf/sprintf use their own explicit format specifiers and are not affected.
  • Mode names are case-insensitive.

Does RunMat run format on the GPU?

format does not interact with GPU tensors. It only affects how values are rendered after being gathered to the host for display.

GPU memory and residency

format is a display-only setting with no effect on GPU residency or acceleration.

Examples

Default short format

format short
pi

Expected output:

ans = 3.1416

Long format for full precision

format long
pi

Expected output:

ans = 3.141592653589793

Scientific notation with short precision

format shortE
pi

Expected output:

ans = 3.1416e+00

Scientific notation with full precision

format longE
pi

Expected output:

ans = 3.14159265358979e+00

Rational approximation

format rat
pi

Expected output:

ans = 355/113

Hexadecimal IEEE 754 representation

format hex
pi

Expected output:

ans = 400921fb54442d18

Resetting to default

format
pi

Expected output:

ans = 3.1416

Using format with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how format changes the result.

Run a small format example, explain the result, then change one input and compare the output.

FAQ

Does format affect computation results?

No. format only changes how values are displayed. Internal precision is always IEEE 754 double.

Is the format setting persistent across cells?

Yes. The setting is stored per-session thread and remains active until changed by another format call.

What is the default format?

format short — 4 decimal places in fixed notation, falling back to scientific for very large or very small values.

Does format affect disp?

Yes. disp and auto-print both use the active format setting. fprintf and sprintf use their own explicit format specifiers and ignore this setting.

Are format mode names case-sensitive?

No. format SHORT, format Short, and format short are all equivalent.

What does format rat do for integers?

Integers are displayed as-is without a denominator (e.g., 42 rather than 42/1). format rational is accepted as an alias for format rat.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how format is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.