format
- : format ¶
- : format
options¶ - : format
(options)¶ - :
[format, formatspacing, uppercase] =format ¶ Query or set how
dispand the interpreter’s automatic echoing lay out numeric values.The setting governs presentation only; it does not alter how numbers are stored or computed. Use a conversion function such as
single,uint8, orint64to change the stored type. Whenever an option changes the count of significant digits shown, that count is also visible throughoutput_precision.Out of the box, Nexus prints about 5 significant digits in a readable layout (the ‘short’, ‘lowercase’, and ‘loose’ options). Calling
formatwith no option, or with ‘default’, returns to this baseline.The floating-point layout options are:
defaultReturn to the baseline layout described above.
shortFixed-point layout with about 5 significant figures; this is the default.
longFixed-point layout with about 16 significant figures.
Like ‘short’, this falls back to an exponential ‘e’ layout when a matrix cannot be shown acceptably in fixed point.
shortelongeExponential layout, where each value is written as a mantissa times a power of ten. The mantissa carries 5 significant digits in the short variant; in the long variant, doubles get 16 significant digits and singles get 8. For instance, ‘shorte’ shows
pias3.1416e+00. The trailing ‘e’ may instead be passed as a separate argument.shortglonggPick whichever of fixed-point or exponential layout suits each value’s magnitude best. For example, ‘shortg’ shows
pi .^ [2; 4; 8; 16; 32]asans = 9.8696 97.409 9488.5 9.0032e+07 8.1058e+15The trailing ‘g’ may instead be passed as a separate argument.
shortenglongengLike ‘shorte’ or ‘longe’, but in engineering style, with the exponent constrained to a multiple of 3. For example, ‘shorteng’ shows
10 * pias31.416e+00. The trailing ‘eng’ may instead be passed as a separate argument.freenonePrint values without aligning matrix columns on the decimal point. This raw layout mirrors the C++ expression
std::cout << variable, giving roughly 6 significant digits and dropping needless precision such as trailing zeros on integers. Complex values appear as a parenthesized pair,(0.60419, 0.60709), rather than as0.60419 + 0.60709i.
The next option applies to every numeric type, floating point and integer alike.
"+""+""chars"plusplus charsReduce each element to a single symbol: ‘+’ for a positive element, ‘-’ for a negative one, and a space for zero. This gives a quick picture of a large matrix’s sparsity pattern, though
spydraws that pattern more clearly for very large matrices.Supplying chars, a string of exactly three characters, overrides the symbols used for positive, negative, and zero entries in that order. For example, under
"+" "+-."the matrix[1, 0, -1; -1, 0, 1]prints asans = +.- -.+
bankShow values as currency amounts, in fixed point with two digits after the decimal point. Only the real part is printed, since an imaginary part is meaningless for money.
bitPrint each number’s bits, most significant bit first, regardless of storage order. For example,
piprints as:0 10000000000 1001001000011111101101010100010001000010110100011000with spaces inserted here to separate the sign bit, the 11-bit exponent, and the 52-bit mantissa, which together encode
pias an IEEE 754 double in normal form. Single-precision values work the same way.native-bitPrint each number’s bits in the machine’s own byte order. On a big-endian host this matches
format bitabove; on a little-endian host the bytes come out reversed, although the bits inside each byte still read most significant first.On x86-64, for example,
piappears as:00011000 00101101 01000100 01010100 11111011 00100001 00001001 01000000again with spaces added for readability; comparing it with the
format bitoutput above shows how the bytes are grouped and reordered.hexAs
format bit, but with the bits collapsed four at a time into hexadecimal digits for compactness. Thuspibecomes:400921fb54442d18
native-hexAs
format native-bit, but with the bits collapsed four at a time into hexadecimal digits. Thuspion x86-64 becomes:182d4454fb210940
ratApproximate each value by a ratio of small integers and print that fraction. For example, ‘rat’ shows
pias355/113.
The next two options control the lettering used in scientific and hexadecimal output.
lowercase (default)Write the exponent marker in scientific notation as a lowercase ‘e’ and the hex digits for 10-15 as lowercase ‘a-f’.
uppercaseWrite the exponent marker as an uppercase ‘E’ and the hex digits for 10-15 as uppercase ‘A-F’.
The next two options control the vertical spacing in matrix output.
compactDrop the blank lines around column-number headers and between matrices, fitting more data on the screen.
loose (default)Keep the blank lines above and below column-number headers and between matrices for a more readable, less dense layout.
When several conflicting options are given at once, the last one takes effect, except that ‘default’ overrides everything else. If any option is invalid the current settings are left untouched.
Called with no inputs and one to three outputs,
formatinstead reports the present numeric layout, the matrix spacing, and the lettering preference. Requesting outputs while also passing inputs is an error.