Compiler Library/XL Reference Manual HP 3000 MPE/iX Computer Systems Edition 2 Manufacturing Part Number: 32650-90029 E1088 U.S.A.
Notice The information contained in this document is subject to change without notice. Hewlett-Packard makes no warranty of any kind with regard to this material, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose. Hewlett-Packard shall not be liable for errors contained herein or for direct, indirect, special, incidental or consequential damages in connection with the furnishing or use of this material.
Print History New editions are complete revisions of the manual. Update packages, which are issued between editions, contain additional and replacement pages to be merged into the manual by the customer. The dates on the title page change only when a new edition or a new update is published. No information is incorporated into a reprinting unless it appears as a prior update; the edition does not change when an update is incorporated.
Additional Documentation More information on the languages and operating system can be found in the following manuals: * HP FORTRAN 77/XL Reference Manual * HP COBOL II Reference Manual * HP COBOL II/XL Reference Manual Supplement * HP Pascal Reference Manual * Trap Handling Programmers' Guide (31501-90010) (31500-90001) (31500-90005) (31502-90001) (32650-90026) Conventions The following conventions are used in this manual: 1. 2. P- 2 All numbers are decimal values unless otherwise noted.
Chapter 1 Introduction The Compiler Library/XL functions and procedures perform input/output, internal data conversion, mathematical functions, error-reporting functions and packed-decimal operations. This chapter describes the format of the function and procedure descriptions, compares data types, shows the internal representation of the data types, and summarizes the functions and procedures in a series of tables.
Special Values When needed, special values are supplied. Compiler Library Data Types Table 1-1 below shows the corresponding data types between HP Pascal, HP FORTRAN 77/XL, HP COBOL II/XL and HP C/XL. NOTE Many of the examples shown in this document are written in Pascal and are described in terms of Pascal and Pascal data types. Table 1-1.
Internal Representation of Data This section shows how different data types are internally represented. Shortint Range: [-32768,32767] in two bytes Representation: Integer Range: [-2147483648,2147483647] in four bytes (concatenated) Representation: Real Range: [-3.402823 x 1038 , -1.401298 x 10-45 ] and 0.0 and 1.401298 x 10-45 , 3.
Representation: For real range of sign bit positive numbers stored in normalized form, the exponent portion has a [1,254] and the fraction portion has a range of [0,223 -1]. The indicates the sign of the fraction portion (0 indicates a value and 1 indicates a negative value). Real numbers in normalized form have an implied value of 1.0 to the left of the fraction's most significant bit. Thus, a normalized decimal value equals (-1)Sign * 2Exponent-127 * (1.
Infinity can also be encoded in the real number format as follows: When all exponent bits are set to 1 and all of the fraction bits are set to 0, there is an Infinity: (-1)Sign Infinity. For example: Exponent = 255; fraction = 0 Longreal Range: [-1.797693134862316 x 10308 ,-4.940656458412465 x 10-324 ] and 0.0 and [4.940656458412465 x 10-324 ,1.
For longreal numbers stored in normalized form, the exponent portion has a range of [1,2046] and the fraction portion has a range of [0,252 -1]. The sign bit indicates the sign of the fraction portion (0 indicates a positive value and 1 indicates a negative value). Longreal numbers in normalized form have an implied value of 1.0 to the left of the fraction's most significant bit. Thus, a normalized decimal value equals the following: (-1)Sign * 2Exponent-1023 * (1.
Table 1-2. Absolute Value Functions --------------------------------------------------------------------------------------------| | | | Function | Description | | | | --------------------------------------------------------------------------------------------| | | | CABS or CABS' | Calculates the absolute value of a complex number. | | | | --------------------------------------------------------------------------------------------| | | | DABS or DABS' | Calculates the absolute value of a longreal number.
Table 1-3. Number Conversion Functions --------------------------------------------------------------------------------------------| | | | Function | Description | | | | --------------------------------------------------------------------------------------------| | | | AINT or AINT' | Truncates a real number to an integer number in real | | | representation.
Table 1-4. Exponent, Root, and Logarithm Functions --------------------------------------------------------------------------------------------| | | | Function | Description | | | | --------------------------------------------------------------------------------------------| | | | ALOG or ALOG' | Calculates the natural logarithm of a positive real number.
Table 1-5. Trigonometry Functions --------------------------------------------------------------------------------------------| | | | Function | Description | | | | --------------------------------------------------------------------------------------------| | | | ATAN or ATAN' | Calculates the arctangent of a real number.
| | | --------------------------------------------------------------------------------------------| | | | DTANH or DTANH' | Calculates the hyperbolic tangent of a longreal number. | | | | --------------------------------------------------------------------------------------------| | | | SIN or SIN' | Calculates the sine of a real number in radians.
Table 1-8. Integer Arithmetic Functions --------------------------------------------------------------------------------------------| | | | Function | Description | | | | --------------------------------------------------------------------------------------------| | | | DADD | Calculates the sum of two integer numbers. | | | | --------------------------------------------------------------------------------------------| | | | DCMP | Compares two integer numbers.
Table 1-11. Packed-Decimal Procedures --------------------------------------------------------------------------------------------| | | | Procedure | Description | | | | --------------------------------------------------------------------------------------------| | | | HPPACADDD | Adds two packed-decimal numbers. | | | | --------------------------------------------------------------------------------------------| | | | HPPACCMPD | Compares two packed-decimal operands and sets a | | | comparison code.
declared by: $ALIAS EXTIN = 'EXTIN"' (%REF, %REF, %VAL, %VAL, %VAL, %VAL, %REF, %REF) or the intrinsic statement could be used: SYSTEM INTRINSIC HPEXTIN In HP C/XL, the intrinsic pragma is used to declare an intrinsic. example, instead of using the following declaration: For extern void HPPACCVDA( ); you could write: #pragma intrinsic HPPACCVDA The function names ending with a prime (EXTIN', for example) can be called by HP Pascal or HP FORTRAN 77/XL programs using the ALIAS command.
Chapter 2 Mathematical Functions and Procedures This chapter describes the mathematical functions and procedures in alphabetical order. NOTE The function names ending with a prime (EXTIN', for example) can be called by HP Pascal programs using the ALIAS command with the EXTERNAL or INTRINSIC statements.
ALOG (or ALOG') or ALOG10 ALOG calculates the natural logarithm of a positive real number; ALOG10 calculates the base 10 logarithm of a positive real number. Declaration FUNCTION ALOG(VAR x:REAL):REAL; EXTERNAL; or FUNCTION ALOG10(VAR x:REAL):REAL; EXTERNAL; Accuracy . . Attributes Parameter: A positive real number. Result: A real number (ALOG10 = ALOG*log10 (e )). HP FORTRAN 77/XL: Intrinsic function ALOG(X) or ALOG10(X).
argument is zero) there are two possible actions. If the INVALID trap is enabled, the message "AMOD(X,Y): ANY OF X AND Y=NaN OR X=INFINITY OR Y=0.0" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. ATAN (or ATAN') ATAN calculates the arctangent of a real number. Declaration FUNCTION ATAN(VAR x:REAL):REAL; EXTERNAL; Accuracy When ~∈ x-y , maximum ∈ ~ f-g 1 + x2 Attributes Parameter: A real number. Result: A representable real number in the range [-pi/2,pi/2].
Attributes Parameters: Real numbers; both must not be zero. Result: A representable real number in one of the following ranges: See Chapter 1 for details on the internal representation of real numbers. HP FORTRAN 77/XL: Intrinsic function: Z=ATAN2(X,Y) Error: If either of the arguments is a NaN or if both arguments are zero (or Infinity), there are two possible actions. If the INVALID trap is enabled, the message "ATAN2(X,Y): X=Y=0.0 OR X=Y=INFINITY OR ANY OF X AND Y=NaN" occurs.
Result: A non-negative real number. HP FORTRAN 77/XL: Intrinsic function: Error: If either part of the argument is a NaN, there are two possible actions. If the INVALID trap is enabled, the message "CABS(X): ANY PART OF X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=CABS(X). If a and/or b are near the overflow threshold (a and/or b approximately equals to 1038 ), the message "CABS OVERFLOW" occurs. See Appendix A for more details.
Attributes Parameter: A complex number. Result: A complex number. HP FORTRAN 77/XL: Callable as a system intrinsic: Error: See the SIN, COS, COSH, and SINH error descriptions. Y=CCOSH(X). CEXP (or CEXP') CEXP calculates ex , where x is a complex number. Declaration Complex numbers in HP FORTRAN 77/XL programs are represented as an ordered pair of real numbers: one for the real part a and one for the imaginary part b. Thus, complex numbers occupy eight bytes.
is a real identifier of the matrix for D, an integer identifier. Result: CINVERT replaces the original matrix, and D equals 1 if the matrix is non-singular or 0 if the matrix is singular and no inverse exists. HP FORTRAN 77/XL: Callable as a system intrinsic: CALL CINVERT(N, A, D) or as a system intrinsic statement. Error: None. CLOG (or CLOG') CLOG calculates the natural logarithm of a complex number.
Attributes Parameter: A real number in radians. Result: A representable real number in the range [-1.0, 1.0]. See Chapter 1 for details on the internal representation of real numbers. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN or an Infinity, there are two cases. If the INVALID trap is enabled, the message "COS(X): X=NaN OR INFINITY" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=COS(X).
Accuracy Depends on the accuracy of SIN, COS, and EXP. Attributes Parameter: A complex number. Result: A complex number. HP FORTRAN 77/XL: Intrinsic function: Error: See the SIN, COS, and EXP error descriptions. Y=CSIN(X). CSINH (or CSINH') CSINH calculates the hyperbolic sine of a complex number. Declaration Complex numbers in HP FORTRAN 77/XL programs are represented as an ordered pair of real numbers: one for the real part a and one for the imaginary part b.
Attributes Parameter: Any complex number representable in two real numbers: one for a and one for b. Result: A complex number. HP FORTRAN 77/XL: Intrinsic function: Error: If any part of the argument is a NaN, there are two cases. If the INVALID trap is enabled, the message "COMPLEX SQRT: ANY PART OF THE ARGUMENT = NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned to both the real and imaginary part. Y=CSQRT(X).
Attributes Parameter: A complex number. Result: A complex number. HP FORTRAN 77/XL: Callable as a system intrinsic: Error: See SIN, COS, SINH, and COSH error descriptions. Y=CTANH(X). DABS (or DABS') DABS calculates the absolute value of a longreal number. Declaration FUNCTION DABS(x:LONGREAL):LONGREAL; EXTERNAL; Attributes Parameter: A longreal number. Result: A longreal number. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN, there are two possible actions.
Attributes Parameter: A longreal number. Result: A representable longreal number in the range [-pi/2, pi/2]. See Chapter 1 for details on the internal representation of longreal numbers. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN, there are two cases. If the INVALID trap is enabled, the message "DATAN(X): X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=DATAN(X).
See Chapter 1 for details on the internal representation of longreal numbers. HP FORTRAN 77/XL: Intrinsic function: Z=DATAN2(X,Y) Error: If either of the arguments is a NaN or if both arguments are zero or infinity, there are two possible actions. If the INVALID trap is enabled, the message "DATAN2(X,Y): X=Y=0.0 OR X=Y=INFINITY OR ANY OF X AND Y=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. See Appendix A for more details.
Result: A representable longreal number in the range [-1.0, 1.0]. See Chapter 1 for details on the internal representation of longreal numbers. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN or an Infinity, there are two cases. If the INVALID trap is enabled, the message "DCOS(X): X=NaN OR INFINITY" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=DCOS(X). When DABS (X) >= 2.6378256 x 107 , DCOS (X) completely loses significance.
Error: If the argument is a NaN, there are two possible actions. If the INVALID trap is enabled, the message "DINT(X) OR DDINT(X): X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. DDIV (or DDIV') DDIV calculates the quotient of one integer number divided by another integer number. See the description of the DREM procedure for the remainder. Declaration FUNCTION DDIV(VAR d1,d2:INTEGER):INTEGER; EXTERNAL; Attributes Parameters: Both arguments are integer numbers.
Special Values dexp (+Infinity) = +Infinity dexp (-Infinity) = 0 DFIX (or DFIX') DFIX truncates a longreal number to an integer number. Declaration FUNCTION DFIX(x:LONGREAL):INTEGER; EXTERNAL; Attributes Parameter: A longreal number. Result: An integer number. HP FORTRAN 77/XL: Callable as a system intrinsic: I = DFIX(X) Error: If traps are enabled and if the truncated longreal number cannot be represented in the two words of the integer, the arithmetic trap INTEGER OVERFLOW occurs.
to 1 if the matrix is non-singular or 0 if the matrix is singular and no inverse exists. HP FORTRAN 77/XL: Callable as a system intrinsic: CALL DINVERT(n, a, d) Error: None. DLOG (or DLOG') or DLOG10 DLOG calculates the natural logarithm of a positive longreal number; DLOG10 calculates the base 10 logarithm of a positive longreal number.
HP FORTRAN 77/XL: Intrinsic function: Z=DMOD(X,Y). Error: If either of the arguments is a NaN (or the first argument is infinity or the second argument is zero), there are two possible actions. If the INVALID trap is enabled, the message "DMOD(X,Y): ANY OF X AND Y=NaN OR X=INFINITY OR Y=0.0" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. DMPY (or DMPY') DMPY calculates the product of two integer numbers.
BY ZERO occurs. DSIGN (or DSIGN') DSIGN calculates the absolute value of the first longreal number and gives the number the sign of the second longreal number. Declaration FUNCTION DSIGN(x,y:LONGREAL):LONGREAL; EXTERNAL; Attributes Parameters: Both arguments are longreal numbers; if the second number is zero, the sign is assumed to be positive. Result: A longreal number. HP FORTRAN 77/XL: Intrinsic function: Error: If either of the arguments is a NaN, there are two possible actions.
Declaration FUNCTION DSINH(VAR x:LONGREAL):LONGREAL; EXTERNAL; Accuracy . Attributes Parameter: A longreal number. Result: A longreal number. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN, there are two possible actions. If the INVALID trap is enabled, the message "DSINH(X): X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=DSINH(X). If DSINH(X) >= 709.
Declaration FUNCTION DSUB(VAR d1,d2:INTEGER):INTEGER; EXTERNAL; Attributes Parameters: An integer number. Result: An integer number. HP FORTRAN 77/XL: Callable as a system intrinsic: Error: If traps are enabled and if the result cannot be represented by an integer, the arithmetic trap INTEGER OVERFLOW occurs. I = DSUB(J,K) DTAN (or DTAN') DTAN calculates the tangent of a longreal number in radians.
Attributes Parameter: A longreal number. Result: A representable longreal number in the range [0.0, 1.0]. See Chapter 1 for details on the internal representation of longreal numbers. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN, there are two possible actions. If the INVALID trap is enabled, the message "DTANH(X): X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=DTANH(X).
Attributes Parameter: A representable real number in the range [-32768.0, 32767.0]. See Chapter 1 for details on the internal representation of real numbers. Result: An integer number. HP FORTRAN 77/XL: Intrinsic function: Error: If traps are enabled and if the real number is outside the range stated, the arithmetic trap INTEGER OVERFLOW occurs. I=IFIX(X). INT (or INT') INT truncates a real number to a shortint number.
number the sign of the second shortint number. Declaration FUNCTION ISIGN(j,k:SHORTINT):SHORTINT; EXTERNAL; Attributes Parameters: Both arguments are shortint numbers; if the second number is zero, the sign is assumed to be positive. Result: An integer number. HP FORTRAN 77/XL: Intrinsic function: Error: None. L=ISIGN(J,K) JSIGN (or JSIGN') JSIGN calculates the absolute value of the first integer number and gives the number the sign of the second integer number.
RAND1 (or RAND1') RAND1 generates a random number, that can be used as the starting point for the RAND procedure. Declaration FUNCTION RAND1: INTEGER; EXTERNAL; Attributes Parameter: None. Result: A 32-bit integer quantity. HP FORTRAN 77/XL: Callable as a system intrinsic:I=RAND1( ) Error: None. Comments This random value is derived from the 31-bit logical quantity changed every millisecond by the MPE XL system timer.
Attributes Parameter: A real number in radians. Result: A representable real number in the range [-1.0, 1.0]. See Chapter 1 for details on the internal representation of real numbers. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN or an Infinity, there are two possible actions. If the INVALID trap is enabled, the message "SIN(X): X=NaN OR INFINITY" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=SIN(X).
Attributes Parameter: A non-negative real number. Result: A non-negative real number. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN or if it is negative, there are two possible actions. If the INVALID trap is enabled, the message "SQRT(X): X<0.0 OR X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=SQRT(X). TAN (or TAN') TAN calculates the tangent of a real number in radians.
Accuracy When x-y ~∈ , maximum f-g ~ ∈ sech2 x Attributes 2- 28 Parameter: A real number. Result: A representable real number in the range [0.0, 1.0]. See Chapter 1 for details on the internal representation of real numbers. HP FORTRAN 77/XL: Intrinsic function: Error: If the argument is a NaN, there are two possible actions. If the INVALID trap is enabled, the message "TANH(X): X=NaN" occurs. Otherwise, the INVALID flag is set. In either case, a quiet NaN is returned. Y=TANH(X).
Chapter 3 Utility Procedures This chapter describes the utility procedures EXTIN'/HPEXTIN and INEXT'/HPINEXT. EXTIN'/HPEXTIN This utility procedure is callable by the names EXTIN' NOTE and HPEXTIN. 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.
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 1 -1 -2 Parameters (Output): SHORTINT REAL INTEGER LONGREAL scale = The scale factor (see Comment 2 for more details). This factor is ignored if datatype=0 (SHORTINT) or datatype=-1 (INTEGER).
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.
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.
Declaration TYPE bytearray = PACKED ARRAY PROCEDURE HPINEXT ( ANYVAR value : datatype : fieldwidth : decplaces : kind : scale : ANYVAR charstring : VAR error : ) OPTION UNCHECKABLE_ANYVAR; EXTERNAL; [1..N] OF CHAR; INTEGER; SHORTINT; SHORTINT; SHORTINT; SHORTINT; SHORTINT; bytearray; SHORTINT Attributes Parameters (Input): value = datatype = 32-bit pointer (address) to the first word of the internal representation to be converted.
Table 3-2. Values of kind and Associated Formats --------------------------------------------------------------------------------------------| | | | | Value of kind | Format | Example | | | | | --------------------------------------------------------------------------------------------| | | | | 3 | Gw.d | See "Comments" for more details. | | | | | | 2 | Dw.d | 0.12345D+04 | | | | | | 1 | Ew.d | 0.12345E+04 | | | | | | 0 | Iw | 1234 | | | | | | -1 | Nw.d | 1,234.5 | | | | | | -2 | Mw.d | $1,234.
Table 3-3. Gw.d Formatting Rules ------------------------------------------------------------------------------------------| | | | Value | Format Used | | | | ------------------------------------------------------------------------------------------| | | | intlvalue < 0.1 | Ew.d | | | | | 0.1 <= intlvalue < 1 | F(w -4).d plus 4 spaces | | | | | 1 < intlvalue < 101 | F(w -4).(d -1) plus 4 spaces | | | | | 101 <= intlvalue < 102 | F(w -4).(d -2) plus 4 spaces | | | | | 102 <= intlvalue < 103 | F(w -4).
decplaces = 3, the following is true: If scale = 0, If scale = -2, If scale = 2, charstring = ÅÅÅ.123E+04 charstring = ÅÅÅ.001E+06 charstring = ÅÅ12.35E+02 When kind = -3, -2, or -1, the result charstring is the internal representation intlvalue multiplied by 10s (where s is scale); the result is then converted. For example, if intlvalue = 1234.5, kind = -3, fieldwidth = 11, and decplaces = 3, the following is true: If scale = 0, charstring = ÅÅÅ1234.500 If scale = -2, charstring = ÅÅÅÅÅ12.
Chapter 4 Packed-Decimal Procedures This chapter describes the packed-decimal procedures that perform the following basic operations: * * * * * Arithmetic operations Comparisons Left and right shifts Conversions to and from binary Conversions to and from external decimal These procedures facilitate migration to MPE XL of applications that perform packed-decimal operations using ASSEMBLE statements in the SPL/V programming language.
Figure 4-1. Packed-Decimal Format The left-most byte in the illustration contains the high-order digit. If this digit is in bit postions 4 through 7, positions 0 through 3 of the same byte are ignored. (A digit count specifies the number of digits to be recognized.) A packed-decimal number has the following characteristics: 4-: 2 * Each decimal digit is represented in binary coded decimal (BCD) form by four bits. * The sign is represented by four bits.
External-Decimal Numbers Figure 4-2 shows the format of external-decimal numbers. Figure 4-2. External-decimal Format External-decimal numbers have the following characteristics: * Each digit is expressed by eight bits. * An indication of the sign of the number is included in the representation of the low-order digit. * In storage, the low-order digit may be any byte of a 32-bit word.
Table 4-1.
Trap Handling When an error is detected by a packed-decimal procedure, the procedure stores information about the operation being performed, the parameters, and the nature of the error, and then causes a trap by executing a reserved instruction. Depending on the state of the MPE XL trap subsystem, the trap may be ignored, the process may be aborted, a user-written trap handler may be invoked, or a Pascal/XL recover block may be executed.
sourcedigs The length of the source field in digits. sourcewords The length of the source field in 16-bit "words." target The receiving field in a conversion. targetdigs The length of the target field in digits. comparison_code NOTE an integer to which the procedure will always return a value of 0, 1, or 2. Comparison_code corresponds to the condition code of the status register on HP 3000 Series V systems.
is passed by value. NOTE The packed-decimal procedures do not alter the condition code associated with the process. Procedure Declarations The procedure declarations in this chapter assume the following Pascal directives and declarations.
op2digs VAR comparison_code VAR pacstatus OPTION DEFAULT_PARMS ( comparison_code pacstatus UNCHECKABLE_ANYVAR; EXTERNAL; :INTEGER; :INTEGER; :INTEGER) :=NIL, :=NIL) Comments Operand1 is compared to operand2 and comparison_code operands remain unchanged at their original addresses. is set. The Possible Traps Invalid packed-decimal digit (3) Invalid decimal operand length (5) HPPACCVAD HPPACCVAD performs an ASCII-to-decimal conversion.
Possible Traps Invalid ASCII digit (2) Invalid decimal operand length (5) HPPACCVBD HPPACCVBD converts a binary number to packed-decimal. Declaration PROCEDURE HPPACCVBD ( ANYVAR target targetdigs ANYVAR source sourcewords VAR comparison_code VAR pacstatus OPTION DEFAULT_PARMS ( comparison_code pacstatus UNCHECKABLE_ANYVAR; EXTERNAL; :decimal_type; :INTEGER; :binary_type; :INTEGER; :INTEGER; :INTEGER) :=NIL, :=NIL) Comments * The source field is converted to packed-decimal and stored in the target field.
comparison_code :=NIL, pacstatus :=NIL) UNCHECKABLE_ANYVAR; EXTERNAL; Comments * The source packed-decimal digits are converted to fill the target field. An unsigned source operand produces an unsigned external-decimal result. When the source is signed, the sign of the result is determined by the two low-order bits of sign_control as described below. sign_control = 0 Target sign is the same as source. sign_control = 1 Target is negative if source is negative. Otherwise, it is unsigned.
--------------------------------------------------------------------------------------------| | | | Source Digit Count | Target "Words" | | | | --------------------------------------------------------------------------------------------| | | | 1 to 4 | 1 | | | | --------------------------------------------------------------------------------------------| | | | 5 to 9 | 2 | | | | --------------------------------------------------------------------------------------------| | | | 10 to 18 | 4 | | | | ---------
--------------------------------------------------------------------------------------------| | | | Source Digit Count | Target "Words" | | | | --------------------------------------------------------------------------------------------| | | | 1 to 4 | 1 | | | | --------------------------------------------------------------------------------------------| | | | 5 to 9 | 2 | | | | --------------------------------------------------------------------------------------------| | | | 10 to 18 | 4 | | | | ---------
the quotient does not exceed 28 digits. undefined. If it does, results are Possible Traps Invalid packed-decimal digit (3) Invalid decimal operand length (5)left arrowFor HPPACDIVD only Decimal divide-by-zero (6) HPPACMPYD HPPACMPYD performs multiplication of two decimal numbers.
Comments * Operand1 is moved to the operand2 field with its digits offset by the shift amount in the low-order five bits of shift_amt. * Leading or trailing digits in the result field that are not supplied by the source operand will be zeros. * If the shift amount is large enough that significant digits of operand1 would be shifted out of the operand2 field, the effective shift amount is reduced so operand1 is left-justified in the operand2 field.
Declaration PROCEDURE HPPACSRD ( ANYVAR operand2 op2digs ANYVAR operand1 op1digs shift_amt VAR comparison_code VAR pacstatus OPTION DEFAULT_PARMS ( comparison_code pacstatus UNCHECKABLE_ANYVAR; EXTERNAL; :decimal_type; :INTEGER; :decimal_type; :INTEGER; :INTEGER; :INTEGER; :INTEGER; :=NIL, :=NIL) Comments * Operand1 is moved to the operand2 field, with its digits offset to the right relative to its sign, by the shift amount in the low-order five bits of shift_amt.
Sample Program This section contains a sample program to demonstrate how to call the packed-decimal library routines. The program takes three large numbers (U.S. federal government annual appropriations for the years 1977 through 1979), converts them from ASCII to packed-decimal, adds them, converts the sum to ASCII, and prints the answer. There are four versions of the program.
HP Pascal/XL Example { This program calculates total appropriations by the United States federal government for the years 1977-1979 } $notes off$ $standard_level 'ext_modcal'$ program appropriations (output); type ascii_num_15 = { 15-digit numbers in ASCII } packed array [1..15] of char; nibble = 0..15; { Half a byte, holds a digit or sign } packed_num_15 = { Holds 15 digits and sign } crunched record digits : crunched array [1..15] of nibble; sign : nibble; end; year_type = 1977..
SYSTEM INTRINSIC HPPACADDD, HPPACCVAD, HPPACCVBD, HPPACCVDA INTEGER*2 ZERO INTEGER YEAR CHARACTER*15 YEARLY (1977:1979) CHARACTER*15 ASCII_SUM ! 15-digit numbers in ASCII CHARACTER*8 PACKED_SUM CHARACTER*8 PACKED_TEMP ! 8-character field holds ! 15 digits and sign DATA YEARLY/ ! Annual appropriations, in cents 1 2 3 '046655980996406', '050778229148999', '056396083378825'/ DATA ZERO/0/ CALL HPPACCVBD (PACKED_SUM, 15, ZERO, 1) ! Initialize sum > DO YEAR = 1977, 1979 PRINT *, YEAR, ' ', YEARLY (YEAR)
ASCII (YEAR, 10, PRINT'BUFFER'B); MOVE PRINT'BUFFER'B (4) := " "; MOVE PRINT'BUFFER'B (7) := YEARLY (15 * (YEAR-1977)), (15); PRINT (PRINT'BUFFER'W, -22, %40); << Convert ASCII to decimal >> TOS := @PACKED'TEMP; TOS := @YEARLY (15 * (YEAR-1977)); ASSEMBLE (CVAD); TOS := 15; TOS := 15; << Add to sum >> TOS := @PACKED'SUM; TOS := 15; TOS := @PACKED'TEMP; TOS := 15; ASSEMBLE (ADDD); END; << Convert sum to ASCII, suppressing plus sign >> TOS := @ASCII'SUM; TOS := 15; TOS := @PACKED'SUM; ASSEMBLE (CVDA ABS); M
4-: 20
Appendix A Compiler Library Error Messages This appendix describes Compiler Library error handling, the intrinsic function XLIBTRAP, and lists error messages. Many of the Compiler Library procedures detect errors in processed data. When error detection occurs, the procedures call an error routine that reports the error conditions and aborts your program. The error message format is as follows: procedure name: message For example, **** ALOG(X): X < 0.
(The HP FORTRAN 77/XL ON statement has additional options that make it easier to use than XLIBTRAP. See the HP FORTRAN 77/XL Reference Manual for more details.) 3. If a user-written error procedure has not been specified by using XLIBTRAP or with the HP FORTRAN 77/XL ON statement and the trap is not to be ignored, the appropriate error report is produced and the current program is aborted. The library trap mechanism is disarmed when the user-written procedure is called.
abort = 1; {This procedure returns a result of -999 and continues the execution of the program if the SQRT routine has the error. Otherwise, the program aborts.} BEGIN IF errornum = sqrt_errornum THEN BEGIN result := sqrt_default; took_trap := True; quit := continue; END ELSE quit := abort; END; {error} {Start the main body of the program.} BEGIN {Set up the -1 value.} x := -1.0; Nan_var := sqrt(x); took_trap := False; {Arm the trap mechanism by calling XLIBTRAP.
A FORTRAN Example Using XLIBTRAP The libtrap_test program in the above example can also be written FORTRAN 77/XL using the ON statement: PROGRAM libtrap_test IMPLICIT NONE REAL x,y,NaN INTEGER INaN EQUIVALENCE (NaN, INaN) DATA INaN / Z'7FF0' / ! bit pattern for single- precision NaN ON EXTERNAL ERROR CALL ERROR ! Set up the trap. PRINT *, 'Calling sqrt with', NaN x=sqrt (NaN) PRINT *, 'x should be -999.0. x=',X PRINT *, 'This should be the last line before an abort.
5 6 7 8 9 CAUSE Both of the arguments are zero or infinity, or any of the arguments is a NaN. ACTION Change the arguments so both of them are not zero or infinity, and neither of the arguments is a NaN. PROCEDURE DATAN2 MESSAGE A. B. C. EXP(X): X=NaN EXP(X) OVERFLOW EXP(X) UNDERFLOW CAUSE A. B. C. The argument is a NaN. The argument is greater than 88.7228. The argument is less than -87.3365. ACTION A. Change the argument so it is not a NaN. B.
10 11 14 15 16 A-6 CAUSE Either or both parts of the complex argument is a NaN. ACTION Change the argument so neither part is a NaN. PROCEDURE CABS MESSAGE SQRT(X): X< 0.0 OR X=NaN CAUSE The argument is less than zero or is a NaN. ACTION Change the argument to be greater than or equal to zero, or not a NaN. PROCEDURE SQRT MESSAGE DSQRT(X): X< 0.0 OR X=NaN CAUSE The argument is less than zero or is a NaN.
17 18 19 20 21 MESSAGE A. B. DCOS(X): X=NaN OR INFINITY DCOS(X): TOTAL LOSS OF PRECISION CAUSE A. The argument is a NaN or infinity. B. The absolute value of the argument is greater than or equal to ...2.637856 x 107 . ACTION A. Change the argument so it is not a NaN or an infinity. B. Change the absolute value of the argument so it is less than or ...equal to 2.637856 x 107 . PROCEDURE DCOS MESSAGE A. B. CAUSE A. The argument is a NaN or infinity. B.
to zero and not a NaN. 22 23 24 25 A-8 PROCEDURE DLOG10 MESSAGE A. B. CAUSE A. The argument is a NaN. B. The absolute value of the argument is greater than 88.7196. ACTION A. Change the argument so it is not a NaN. B. Change the argument so its absolute value is less than or equal to 88.7196. PROCEDURE SINH MESSAGE A. B. CAUSE ACTION A. The argument is a NaN. B. The absolute value of the argument is greater than 709.7795518826419. A. Change the argument so it is not a NaN. B.
26 27 28 29 30 31 34 MESSAGE ASIN(X): |X| > 1.0 OR X=NaN CAUSE The absolute value of the argument is greater than 1.0 or the argument is a NaN. ACTION Change the argument so its absolute value is not greater than zero and the argument is not a NaN. PROCEDURE ASIN MESSAGE DASIN(X): |X| > 1.0 OR X=NaN CAUSE ACTION The absolute value of the argument is greater than 1.0 or the argument is a NaN. Change the argument so its absolute value is not greater than zero and the argument is not a NaN.
36 37 38 39 41 42 A-10 CAUSE ACTION The argument is a NaN. Change the argument so it is not a NaN. PROCEDURE DABS MESSAGE TANH(X): X=NaN CAUSE The argument is a NaN. ACTION Change the argument so it is not a NaN. PROCEDURE TANH MESSAGE DMOD(X,Y): ANY OF X AND Y=NaN OR X=INFINITY OR Y=0.0 CAUSE Either or both of the arguments are NaN, or X=infinity, or Y=0.0. ACTION Change the arguments so neither of them is a NaN, X is not infinity, and Y is not zero.
47 PROCEDURE DDINT or DDINT' MESSAGE SIGN FUNCTION: ANY ARGUMENT = NaN CAUSE Either or both of the arguments are NaN. ACTION Change the arguments so neither of them is a NaN.