\(\text{FileReadReal}\)¶
You can use the the \(\text{FileReadReal}\) function to read a single single precision or double precision real value.
You can use the \filereadreal
backslash command to insert this function.
The following variants of this function are available:
\(\text{tuple } \text{FileReadReal} \left ( \text{<file number>} \right )\)
\(\text{tuple } \text{FileReadReal} \left ( \text{<file number>}, \text{<size/endian>} \right )\)
The \(\text{<file number>}\) parameter is an integer value returned by one of the \(\text{FileOpen}\ldots\) functions. The \(\text{<size/endian>}\) parameter indicates how the real value to be read is encoded in the file.
If the \(\text{<size/endian>}\) value is not included or is 0, then the
\(\text{FileReadReal}\) function assumes that the real is encoded as a
string, either with a fixed point representation such as -123.4
or an
exponent representation such as -1.234E2
. The real value can be positive
or negative, including a leading +
character and the exponent character
E
can be upper or lower case. In this mode, the
\(\text{FileReadReal}\) function will read up-to but excluding the first
non-digit character.
If the \(\text{<size/endian>}\) value is +4 or +8, then the \(\text{FileReadReal}\) function will read the real value in little-endian single or double precision format conforming to IEEE 754-2008. That is, the least significant bit of the mantissa will be at the first (lowest) position in the file.
If the \(\text{<size/endian>}\) value is -4 or -8, then the \(\text{FileReadReal}\) function will real the real value in big-endian single or double precision format conforming to IEEE 754-2008. That is, the sign bit will be at the most significant bit of the byte at the first (lowest) position in the file.
The \(\text{FileReadReal}\) function will return a tuple containing two entries:
The real value read from the file.
A boolean holding
true
on success orfalse
on error.
The Figure 136 shows how you can use the \(\text{FileReadReal}\) function.