通过表格形式显示数组,语法如下
table( [, ,..., ], , , )
array_1
An array of values for column 1.
array_2
An optional array of values for column 2.
array_n
An optional array of values for column n.
format
A format descriptor for each column in the table.
from
The index of the first element in each column.
to
The index of the last element in each column.
{label = {"zero", "one", "two", "three", "four"} }
{c0 = {" ", "I", "II", "III", "IV", "V", "VI"} }
{c1 = {0, 1, 2, 3, 4, 5, 6} }
{table(label, c0, c1, "%8s %8s %4d", 0, 3)}
{label = {"zero", "one", "two", "three", "four"} }
{c0 = {" ", "I", "II", "III", "IV", "V", "VI"} }
{c1 = {0, 1, 2, 3, 4, 5, 6} }
{table(label, c0, c1, "%8s %8s %4d", 0, 4)}
{label = {"zero", "one", "two", "three", "four"} }
{c0 = {" ", "I", "II", "III", "IV", "V", "VI"} }
{c1 = {0, 1, 2, 3, 4, 5, 6} }
{table(label, c0, c1, "%8s %8s %4d", 1, 6)}
设置字符的格式语法如下:
format, %[].[][], []
width
An optional parameter that specifies the minimum number of characters to be printed.
precision
An optional parameter that specifies the number of digits to the right of the decimal point.
type
An optional parameter that specifies the format of the output:
i/d
integer
f
floating point
e/E
scientific notation
g/G
auto-format
o
octal
x/X
hexadecimal
c/C
single character
s/S
string
optional parameter
An optional parameter that displays the output in one of three formats:
Displays the contents of an array as comma-separated lists.
Displays the contents of an array as elements inside of braces with each element in the array surrounded by braces and separated by commas.
Displays the contents of an array as rows and columns of values bounded by vertical bars.
{format, %i, list}
{square1 = { {1.3, 2.9},
{3.1, 4.2} } }
{square1}
{square1, %i, array}
{square1, %i, matrix}
Template:
{format, %9.7f}
{sin(PI/4)}
{sin(PI/4), %5.2f}
Output:
0.7071067
0.71
计算线性方程
3x + 4y + 9z = 29
5x - 3y + z = 16
x + y + z = 4
{ 3, 5, 1 } } =
{ 4, -3, 1 } } =
{ 9, 1, 1 } } =
{ 29, 16, 4 }' } =
{x_coeffs, y_coeffs, z_coeffs}' } =
%5.2f, matrix}
coefficient matrix:
{lhs}
right hand side:
{rhs}
determinant:
{determinant(lhs)}
inverse:
, %7.4f}
inverse times original:
* lhs}
answer:
* rhs}
Formatting general output, numeric output, character and string output, and matrices.
Templex writes text to the specified output stream exactly as it appears in the template.
For example:
{X=3}
What is X + 2?
The answer is: {X + 2}
appears as:
What is X + 2?
The answer is: 5
Templex uses standard C format descriptors to format numeric and string output. Format descriptors reserve a specific amount of space in the output text for the value. If more space is reserved than the value requires, the output text is padded with spaces. Numerical values are right justified. String values are left justified.
If no format is specified, each data type uses the default format associated with each variable type or the default template format and the output is not padded. A default template format is created using the Templex statement. format
Format descriptors are placed at the end of an expression. They are separated from the expression by a comma and preceded by a percent sign, %. The following examples illustrate the syntax:
{sqrt(100), %5d}
{cos(t) + sin(3.1415/phi), %12.5f}
Of the twelve spaces in the second example, five spaces are used to display the values to the right of the decimal point. One space is reserved for the decimal point. The six remaining spaces appear to the left of the decimal point as a blank and a zero.
Extra space does not need to be reserved for the leading plus/minus sign. Some operating systems display a blank instead of a plus sign.
Integer and real values can be displayed in six output formats: integeroctal, hexadecimal, floating point, scientific notation, and value dependent. Descriptors for these formats and examples of their use are given in the following table.
Data Format | Descriptor | Example | Output |
---|---|---|---|
Integer | d or i |
|
|
Octal | o | {100, %4o} | •144 |
Hexadecimal | x or X | {100, %4X} | ••64 |
Floating point | f | {sin(PI/4), %6.3f} | •0.707 |
Scientific notation | e or E |
|
|
Value-dependent | g or G |
|
|
Note: The • in the output column indicates blank spaces which are used to pad the output if the reserved space is not completely used. The • does not appear in your output.
The and descriptors automatically determine whether a fixed decimal or exponential notation format should be used, depending on the magnitude of the result. If the magnitude of the value is large, the descriptor uses a capital in the exponent, depending on your operating system’s defaults.g
G
G
E
Character and string values can be displayed in two output formats, as single characters or as strings. Descriptors for these formats and examples of their use are given in the following table:
Data Format | Descriptor | Example | Output |
---|---|---|---|
single character | c | {65, %c} | A |
character string | s | {"This is a string", %.12s} | This is a st |
templex.hichar
0
1
Matrices can be displayed in three output formats: as a comma-separated list, as a list of elements inside braces, and as rows and columns of numbers. The parameters for these three formats and examples of each are given in the following table:
Data Format | Descriptor | Example | Output |
---|---|---|---|
comma-separated lists | list |
|
|
elements inside of braces | array |
|
|
rows and columns | matrix |
|
|