EXTIN'/HPEXTIN [ Compiler Library/XL Reference Manual ] MPE/iX 5.0 Documentation
Compiler Library/XL Reference Manual
EXTIN'/HPEXTIN
This utility procedure is callable by the names EXTIN' and HPEXTIN.
NOTE EXTIN' is provided for compatibility with MPE V. In new program
development, it is advisable to call HPEXTIN for ease of use. The
declaration is the same for both utility names.
EXTIN'/HPEXTIN converts a byte array containing an input string of ASCII
digits into one of these internal representations:
* SHORTINT
* REAL
* INTEGER
* LONGREAL
See the "Comments" section for more details.
Declaration
TYPE bytearray = PACKED ARRAY [1..N] OF CHAR;
PROCEDURE HPEXTIN (
ANYVAR charstring : bytearray;
VAR stringlen : SHORTINT;
decplaces : SHORTINT;
datatype : SHORTINT;
scale : SHORTINT;
delimiters : SHORTINT;
ANYVAR result : INTEGER;
VAR error : SHORTINT
)
OPTION UNCHECKABLE_ANYVAR;
EXTERNAL;
Attributes
Parameters charstring = The byte array to be converted, passed
(Input): by reference.
stringlen = Upon entry, the field width of the
ASCII input string including all
special characters. (See Comment 1 for
more details.)
decplaces = The number of digits d to be
interpreted as fraction digits
(multiply the integer field by 10-d if
the input string does not include a
decimal point). See Comment 1 for more
details. If a decimal point is
included in the input string, this
parameter has no effect. If decplaces
is less than zero, the procedure
assumes decplaces is zero. If datatype
is 0 or -1, this parameter is ignored.
datatype = The internal representation desired:
0 = SHORTINT
1 = REAL
-1 = INTEGER
-2 = LONGREAL
scale = The scale factor (see Comment 2 for
more details). This factor is ignored
if datatype=0 (SHORTINT) or datatype=-1
(INTEGER).
delimiters = Imbedded blanks, dollar signs, and
commas in the input are treated
differently, depending upon whether the
value is even or odd.
Even: $ and/or commas and/or
imbedded blanks are
delimiters.
Odd : Imbedded blanks are
treated as zeros; a $
and/or a comma to the
left of every third
digit to the left of
the decimal point are
allowed.
Parameters result= 32-bit pointer (address) to the first
(Output): word of result storage according to the
type specified.
error = Error indicator (see Comments 5 and 6
for more details).
2 = No integer or fraction
value was detected
(see Comment 6).
1 = An illegal character
was detected (see
Comment 5).
0 = Valid result; no
error.
-1 = The number is larger
than the largest
representable value
and an illegal
character was
detected.
-2 = The resulting number
is greater than the
largest representable
value of datatype.
See Chapter 1 for
details on
representable values.
-3 = The number is less
than the smallest
representable value
and an illegal
character was
detected.
-4 = The resulting number
is less than the
smallest representable
value of datatype.
See Chapter 1 for
details on
representable values.
W = Upon exit, the number
of string characters
used to compute the
result (see Comment
5).
Results: See "Parameters (Output)" above.
HP FORTRAN 77/XL: Use the $ALIAS directive to call EXTIN' ; use
the system intrinsic statement to call
HPEXTIN.
Errors: See "Parameters (Output)" above.
Comments
1. The external form of the input is a string of ASCII digits that
can include integer, fraction, and exponent subfields:
Integer Fraction Exponent
field field field
| | |
V V V
|<---------->| |<----------->| |<---------->|
+n...n . n...n E+ee
^
|
Decimal point
The exponent field input can be any of these forms:
+e +ee Ee Eee De Dee
-e -ee E+e E+ee D+e D+ee
+eee -eee E-e E-ee D-e D-ee
where e is an exponent value digit.
2. The scale parameter has no effect if the input string includes an
exponent field. Otherwise, a scale of n sets the result to the
input string value * 10-n . For example,
STRING Array scale RESULT
------------ ----- ------
4398.76 3 4.39876
543.21 -3 543210.
3. The type of the result is independent of the input string format.
For example, the input 4398.76 can be converted to integer form.
The conversion rules are stated in Table 3-1.
Table 3-1. Rules for Data Type Conversion
---------------------------------------------------------------------------------------------
| | | |
| Data Type | Value of datatype | Result |
| | | |
---------------------------------------------------------------------------------------------
| | | |
| SHORTINT | 0 | Truncates a fractional input. |
| | | |
| REAL | 1 | Accepts a fractional input. |
| | | |
| INTEGER | -1 | Truncates a fractional input. |
| | | |
| LONGREAL | -2 | Accepts a fractional input. |
| | | |
---------------------------------------------------------------------------------------------
4. Leading blanks in the input string are ignored; if the parameter
delimiters is odd, trailing blanks are treated as zeros.
5. If error is set to an odd value, an illegal character was input;
if error is odd and negative, an illegal character and illegal
value was detected. The parameter intlvalue is computed from the
input string characters that preceded the delimiting digit or
illegal character. Parameter stringlen can be used as an index
into charstring to locate that delimiter or illegal character.
The following are examples of illegal character inputs:
+1.345A (A is illegal)
7543CUP (C, U, and P are illegal)
6. If error is set to 2, no integer or fraction value was detected
and a result cannot be computed. The following are examples of
non-value inputs:
+.E5 (the exponent E5 has no base)
-.A (no base, no exponent)
7. When case is significant, the names for the EXTIN'/HPEXTIN
procedure are in lower case.
NOTE Dollar signs ($) and commas for monetary or numeration form in the
input are ignored, but they must be counted in parameter stringlen,
and must be in the proper places (for example, $ must lead a
number, and commas should appear every third digit).
MPE/iX 5.0 Documentation