0
\$\begingroup\$

Here are the two variants of the write function that can be used to write the "real" data type into file or stdout.

TEXTIO.WRITE[std.TEXTIO.LINE, std.STANDARD.REAL, std.STANDARD.STRING    

TEXTIO.WRITE[std.TEXTIO.LINE, std.STANDARD.REAL, std.TEXTIO.SIDE, NATURAL, NATURAL]

I am just trying to understand how to use the optional parameters.

First the string parameter in the first function. I believe it is possible to specify how the format the real number but I have not found any examples of it it is supposed to be used.

Now for the side and natural parameters for the second function. I believe that the side parameter value can be left or right. This is how the real number being written must be justified. What about the natural number parameters?

\$\endgroup\$
2
  • \$\begingroup\$ Your question itself doesn't define 'optional parameters'. The declaration matching your second 'signature' is found in 16.4 Package TEXTIO showing parameters having default expressions. 6.5.7 Association lists 6.5.1 General "...For an interface element that is a formal generic constant, a formal signal port, or a formal variable or constant parameter, if the association element is not included in the association list, or if the actual is open, then the value of the default expression is used as the actual expression..." The idea here to not confuse readers. \$\endgroup\$ Apr 12 at 0:57
  • \$\begingroup\$ The optional parameters are of the String, Side and Natural type. I am calling them optional since the function can be used without assigning value to them. \$\endgroup\$
    – quantum231
    Apr 12 at 14:45

1 Answer 1

1
\$\begingroup\$

From 1076-2019:

For

procedure WRITE (L: inout LINE; VALUE: in REAL; JUSTIFIED: in SIDE:= RIGHT; FIELD: in WIDTH := 0; DIGITS: in NATURAL:= 0);

Parameter DIGITS specifies how many digits to the right of the decimal point are to be output when writing a real number; the default value 0 indicates that the number should be output in standard form, consisting of a normalized mantissa plus exponent (e.g., 1.079236e-23). If DIGITS is non-zero, then the real number is output as an integer part followed by '.' followed by the fractional part, using the specified number of digits (e.g., 3.14159).

For:

procedure WRITE (L: inout LINE; VALUE: in REAL; FORMAT: in STRING);

Parameter FORMAT specifies how values of type REAL are to be formatted.

From 5.2.6: With the FORMAT parameter, the format of the result is determined using the value of the FORMAT parameter in the manner described in ISO/IEC 8859-1:1998, ISO/IEC 9899:2018 for the C fprintf function. A model is erroneous if it calls the operation with a value for the FORMAT parameter that is other than a conversion specification in which the conversion specifier is one of e, E, f, F, g, G, a, or A. Moreover, the model is erroneous if the conversion specification contains a length modifier or uses an asterisk for the field width or precision. An implementation shall support use of the conversion specifiers e, E, f, g, and G, and may additionally support use of the conversion specifiers F, a, and A. A model is erroneous if it calls the operation with a value for the FORMAT parameter that is a conversion specification in which the conversion specifier is one of F, a, or A and the implementation does not support use of the conversion specifier. The values of FLT_RADIX and DECIMAL_DIG (described in ISO/IEC 8859-1:1998, ISO/IEC 9899:2018) are implementation defined.

If you need the C format string and it does not provide the right or left justification you need, you can use the WRITE for a string (it has justification as part of it) and then create the string with:

function TO_STRING (VALUE: REAL; DIGITS: NATURAL) return STRING;
function TO_STRING (VALUE: REAL; FORMAT: STRING) return STRING;
\$\endgroup\$
5
  • \$\begingroup\$ 16. 4 Package TEXTIO "Parameter FORMAT specifies how values of type REAL are to be formatted. The formatting is determined in the same manner as for the TO_STRING operation for type REAL with the FORMAT parameter (see 5.2.6)." ISO/IEC 9899:2018 is C17. \$\endgroup\$ Apr 12 at 0:57
  • \$\begingroup\$ @user16145658 Exactly. Rather than adding filler text that referred to 5.2.6, I put in the text from 5.2.6. Cool right! That way it has more meaning than the stuff you quoted. \$\endgroup\$
    – Jim Lewis
    Apr 12 at 2:29
  • \$\begingroup\$ Since the size of the number changes, I want to specify a length for the field. If the field is smaller than add padding using ' ' or some other specified character. If the field is larger than obviously no padding. Is it possible to add such padding in both variants of the function call? \$\endgroup\$
    – quantum231
    Apr 12 at 14:48
  • \$\begingroup\$ Write your own to_string function with your own particular formatting for real and use the write[line, string] procedure in package TEXTIO. If you. Intend to evaluate the output TEXT file real in VHDL you'd need the complimentary functionality reading. \$\endgroup\$ Apr 13 at 8:27
  • \$\begingroup\$ You can use VHDL-2008 to_string and justify separately. \$\endgroup\$
    – Jim Lewis
    Apr 30 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.