PreviousUpNext

11.3.3  Printf Sprintf Fprintf Format Strings

Mythryl supports the following basic format specifiers:

Zero or more of following modifiers may follow the percent in a format specifier:

A decimal field width is allowed after the above modifiers (if any).

In the case of the floating point specifiers (that is, ’E’, ’e’, ’f’, ’G’, ’g’), the width field may be followed by a decimal point and a decimal precision.

No other format specifiers or modifiers are currently supported.

Integer types other than Int must currently be converted to string form using other facilities, typically the to_string function in the relevant package or else the underlying sfprintf package.

(Mapping of basic format specifiers to meaning is done in src/lib/src/printf-field.pkg.)

Examples:

eval:  printf "%12s\n" "foo";
         foo

eval:  printf "%-12s\n" "foo";
foo         

eval:  printf "%12s%12s\n" "foo" "bar";
         foo         bar

eval:  printf "%-12s%-12s\n" "foo" "bar";
foo         bar         

eval:  printf "%B\n" ("foo"=="bar");
FALSE

eval:  printf "%f\n" pi;
3.141593

eval:  printf "%g\n" pi;
3.14159

eval:  printf "%e\n" pi;
3.141593e00

eval:  printf "%E\n" pi;
3.141593E00

eval:  printf "%15.7g\n" pi;
       3.141593

eval:  printf "%15.10g\n" pi;
    3.141592654

eval:  printf "%f\n" (pi*1000.0*1000.0);
3141592.653590

eval:  printf "%g\n" (pi*1000.0*1000.0);
3.14159e06

eval:  sprintf "%g\n" (pi*1000.0*1000.0);
"3.14159e06\n"

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext