[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP Pascal for OpenVMS
|
Previous | Contents | Index |
Literal values of the INTEGER type have the following form:
{ decimal-number } { base-number#[[']]extended-digit[[']] } {- } { } [[ { } ]] { {b } } {+ } { % {o } [[']]extended-digit[[']] } { { } } { {x } } { } |
decimal-number
Specifies an integer in conventional Pascal integer notation. You cannot specify commas or decimal points. Examples of decimal notation are as follows:
17 0 89324base-number
Specifies the base, or radix, of the number. HP Pascal accepts numbers in bases 2 through 36.extended-digit
Specifies the notation that is appropriate for the specified base.b
o
x
Specifies an integer in either binary (base 2), octal (base 8), or hexadecimal (base 16) notation. In HP Pascal you can use either uppercase or lowercase letters to specify the extended-digit notation.
You can use extended-digit notation in the same way
you use the conventional integer notation. The one restriction is that
you cannot use extended-digit values as labels.
HP Pascal allows the use of spaces and tabs to make the
extended-digit notation easier to read. To use spaces and tabs, enclose
the extended digit in single quotation marks (' ').
The following are integer values in the extended-digit notation:
2#10000011 2#'1000 0011' 32#1J -16#'7FFF FFFF' |
HP Pascal provides another extended-integer convention only for the sake of compatibility with previous versions of the language. The following are extended-integer values in the HP Pascal specific notation:
%b'1000 0011' %O'7712' -%x'DEC' |
Range of Integer Values | Data Type |
---|---|
- MAXINT64...( - MAXINT) -1 | INTEGER64 |
- MAXINT...MAXINT | INTEGER |
MAXINT+1...MAXINT64 | INTEGER64 |
MAXINT64+1...MAXUNSIGNED64 | UNSIGNED64 |
Range of Integer Values | Data Type |
---|---|
- MAXINT...MAXINT | INTEGER |
MAXINT+1...MAXUNSIGNED | UNSIGNED |
To force an INTEGER constant to become UNSIGNED, INTEGER64, or UNSIGNED64, you can use the UINT, INT64, or the UINT64 predeclared routines, respectively.
To force an UNSIGNED constant to become INTEGER64 or UNSIGNED64, you can use the INT64 or UINT64 predeclared routines, respectively.
To force an INTEGER64 constant to become UNSIGNED64, you can use the UINT64 predeclared routine.
The INTEGER_ADDRESS data type has the same underlying size as a pointer. INTEGER_ADDRESS is equivalent to the INTEGER data type.
The CHAR data type consists of single character values from the ASCII character set. The largest possible value of the CHAR type is the predefined constant MAXCHAR.
To specify a character constant, enclose a printable ASCII character in single quotation marks. To specify the single-quote character, enclose two single quotation marks in single quotation marks. Each of the following is a valid character constant.
'A' 'z' '0' { This is the character 0, not the integer value 0 } '''' { The apostrophe or single quotation mark } '?' |
You can also specify a character constant by enclosing printable ASCII characters in double quotation marks. To specify the double-quote character when using double quotation marks as delimiters, use the \" escape sequence. Each of the following is a valid character constant:
"A" "z" "\"" { The double quotation mark } "?" |
The ORD function accepts parameters of type CHAR. The function return
value is the ordinal value of the character in the ASCII character set.
You can specify a nonprinting character, such as a control character,
by writing an empty string followed immediately by the ordinal value of
the character in the ASCII character set, or by using the CHR function
followed by the ordinal value of the character in the ASCII character
set. The following examples show the two ways to specify the bell
control character:
''(7) CHR( 7 ) |
You can also specify certain nonprinting characters with syntax like
that of the C programming language. Enter the predefined constant for
the character within double quotation marks. For example, to specify
the line-feed character, enter:
"\n" |
Boolean values are the result of testing relationships for truth or validity. The BOOLEAN data type consists of the two predeclared identifiers FALSE and TRUE. The expression ORD( FALSE ) results in the value 0; ORD( TRUE ) returns the integer 1.
The relational operators operate on the ordinal, real, string, or set expressions, and produce a Boolean result.
An enumerated type is a user-defined ordered set of constant values specified by identifiers. It has the following form:
({enumerated-identifier},...) |
enumerated-identifier
The identifier of the enumerated type being defined. HP Pascal allows a maximum of 65,535 identifiers in an enumerated type.
The values of an enumerated type begin with the value 0 and follow a left-to-right order. Subsequent identifiers have a value one greater than the identifier preceding it. Consider the following:
TYPE Seasons = ( Spring, Summer, Fall, Winter ); VAR Some_Seasons : Seasons VALUE Winter; {Initialized} |
In this enumerated type, Spring (value 0) and Summer (value 1) are less than Fall (value 2) because they precede Fall in the list of constant values. Winter (value 3) is greater than Fall because it follows Fall.
The ORD function accepts expressions of an enumerated type.
An identifier in an enumerated type cannot be defined for any other purpose in the same block. Consider the following:
TYPE Seasons2 = ( Fall, Winter, Spring ); |
This enumerated type cannot be defined in the same block as the previous type, because the identifiers Spring, Fall, and Winter would not be unique.
On the ORD function ( Section 8.65)
2.1.5 Subrange Types
A subrange type is user-defined and specifies a limited portion of another ordinal type (called the base type). It has the following form:
lower-bound..upper-bound |
lower-bound
A constant expression or a formal discriminant identifier that establishes the lower limit of the subrange.upper-bound
A constant expression or formal discriminant identifier that establishes the upper limit of the subrange. The value of the upper bound must be greater than or equal to the value of the lower bound.
The base type can be any enumerated or predefined ordinal type. The values in the subrange type appear in the same order as they are in the base type. For example, the result of the ORD function applied to a value of a subrange type is the ordinal value that is associated with the relative position of the value in the base type, not in the subrange type.
You can use a subrange type anywhere in a program that its base type is legal. A value of a subrange type is converted to a value of its base type before it is used in an operation. All rules that govern the operations performed on an ordinal type pertain to subranges of that type.
Consider the following:
TYPE Day = ( Mon, Tues, Wed, Thur, Fri, Sat, Sun ); Weekday = Mon..Fri; {subrange of base type Day} Weekend = Sat..Sun; {subrange of base type Day} Digit = '0'..'9'; {subrange of base type CHAR} Month = 1..31; {subrange of base type INTEGER} National Debt = 1..92233720368 {subrange of base type INTEGER64} 5477580; |
Using size attributes with subrange types might lead to confusion when combined with subrange checking. Consider the following:
type word = [word] 0..65535;procedure take_a_word( p : word ); begin writeln(p); end; begin take_a_word(90000); end. |
When HP Pascal passes value parameters of a subrange type, the actual parameter is evaluated as an expression of the base type (INTEGER in the above case). This allows the actual parameter to be larger than the size attribute in the subrange. This is done to allow the subrange check in the called routine to function properly. For value parameters, HP Pascal allocates a local variable of the parameter's type and then assigns the parameter into the local variable. That local variable is then used throughout the body of the routine wherever the parameter is referenced. Subrange checking is performed when an expression of the base type is assigned into a subrange variable. Therefore the above routine is similar to the following:
procedure take_a_word( p_ : integer ); var p : word; { Local copy } begin p := p_; { Make local copy and do range check from longword integer expression into word subrange on assignment } writeln(p); end; |
This means that HP Pascal will fetch an entire longword from P_ when making the local copy. If you call Pascal functions from non-Pascal routines with value parameters that are subranges, you must pass the address of a value with the size of the base type. If subrange checking is disabled, the compiler can assume that the actual parameter is in range and can only fetch a word since that is sufficient to represent all valid values.
If the parameter was a VAR parameter, then the compiler would indeed only fetch a word since the formal parameter is an alias for the actual parameter and you are not allowed to pass expressions to a VAR parameter. The compiler assumes that the VAR parameter contains a valid value of the subrange. In other words, subranges are checked at assignment time and are considered valid when fetched.
HP Pascal predefines the REAL, SINGLE, DOUBLE, and QUADRUPLE data types in the floating-point formats listed in Table 2-7.
In this manual, the term REAL type refers to both the REAL and SINGLE types.
Data Type | Format | Precision | Default on |
---|---|---|---|
Single-precision REAL types 1 | VAX F_floating-point format 3 |
1 part in 2
23 =
7 decimal digits |
OpenVMS VAX,
OpenVMS Alpha |
IEEE S_floating-point format |
1 part in 2
23 =
7 decimal digits |
OpenVMS I64 | |
Double-precision DOUBLE types 1,2 | VAX D_floating-point 2 3 |
1 part 2
55 =
16 decimal digits |
OpenVMS VAX |
VAX G_floating-point format 3 |
1 part in 2
52 =
15 decimal digits |
OpenVMS Alpha | |
IEEE T_floating-point format |
1 part in 2
52 =
15 decimal digits |
OpenVMS I64 | |
QUADRUPLE | VAX H_floating-point format |
1 part in 2
112 =
33 decimal digits |
OpenVMS VAX |
IEEE X_floating-point format |
1 part in 2
112 =
33 decimal digits |
OpenVMS I64,
OpenVMS Alpha |
HP Pascal also provides data types to allow the selection of floating types independent of the setting of the FLOAT qualifier or attribute. Table 2-8 identifies the built-in types available by system.
Data Type | System |
---|---|
F_FLOAT | OpenVMS I64, OpenVMS Alpha, OpenVMS VAX |
D_FLOAT | OpenVMS I64, OpenVMS Alpha, OpenVMS VAX |
G_FLOAT | OpenVMS I64, OpenVMS Alpha, OpenVMS VAX |
H_FLOAT | OpenVMS VAX |
S_FLOAT | OpenVMS I64, OpenVMS Alpha, OpenVMS VAX |
T_FLOAT | OpenVMS I64 and OpenVMS Alpha |
X_FLOAT | OpenVMS I64 and OpenVMS Alpha |
To express REAL numbers, you can use either decimal or exponential notation. To express DOUBLE or QUADRUPLE numbers, you must use exponential notation.
To express REAL numbers in decimal notation, use the set of decimal digits and a decimal point. At least one digit must appear on either side of the decimal point. The following are valid real numbers in decimal notation:
2.4 893.2497 8.0 0.0 |
To express real numbers in exponential notation, you include a real number or an integer, an uppercase or lowercase letter indicating the type of precision, and an integer exponent with its minus sign or optional plus sign. For example:
2.3E2 10.0E-1 9.14159e0 |
Table 2-9 presents the letters that indicate precision in exponential notation.
Letters | Meaning |
---|---|
E or e | Single-precision real number. The integer exponent following this letter specifies the power of 10. |
D or d | Double-precision real number. All double-precision numbers in your program must appear in this exponential format; otherwise, the compiler reverts to single-precision representation. |
Q or q | Quadruple-precision real number. All quadruple-precision numbers in your program must appear in this exponential format; otherwise, the compiler reverts to single-precision format. On systems that do not support the quadruple data type, the letters Q and q are treated as double-precision numbers (D). |
To express negative real numbers in exponential notation, use the negation operator (-). Remember that a negative real number such as -4.5E+3 is not a constant, but is actually an expression consisting of the negation operator (-) and the real number 4.5E+3. Use caution when expressing negative real numbers in complex expressions.
Table 2-10 presents the identifiers that are predefined by HP Pascal for use with the real data types.
Identifier | Value |
---|---|
Single-Precision F_floating | |
MINREAL | 2.938736E-39 |
MAXREAL | 1.701412E+38 |
EPSREAL 1 | 1.192093E-07 |
IEEE Single-Precision S_floating | |
MINREAL | 1.175494E-38 |
MAXREAL | 3.402823E+38 |
EPSREAL | 1.192093E-07 |
Double-Precision D_floating | |
MINDOUBLE | 2.938735877055719E-39 |
MAXDOUBLE | 1.701411834604692E+38 |
EPSDOUBLE | 2.77557561562891E-17 (OpenVMS VAX) |
2.22044604925031E-16 (OpenVMS I64 and OpenVMS Alpha) | |
Double-Precision G_floating | |
MINDOUBLE | 5.56268464626800E-309 |
MAXDOUBLE | 8.98846567431158E+307 |
EPSDOUBLE | 2.22044604925031E-016 |
IEEE Double-Precision T_floating | |
MINDOUBLE | 2.2250738585072014E-308 |
MAXDOUBLE | 1.7976931348623157E+308 |
EPSDOUBLE | 2.2204460492503131E-016 |
Quadruple-Precision H_floating | |
MINQUADRUPLE | 8.40525785778023376565669454330438E-4933 |
MAXQUADRUPLE | 5.94865747678615882542879663314004E+4931 |
EPSQUADRUPLE | 1.92592994438723585305597794258493E-0034 |
IEEE Quadruple-Precision X_floating | |
MINQUADRUPLE | 3.36210314311209350626267781732175E-4932 |
MAXQUADRUPLE | 1.18973149535723176508575932662801E+4932 |
EPSQUADRUPLE | 9.62964972193617926527988971292464E-0035 |
Previous | Next | Contents | Index |