HP 3000 Manuals

Simple Types [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation


HP Pascal/iX Reference Manual

Simple Types 

The simple data types are made up of ordinal, real, and longreal types.
Ordinal types include the standard types integer, char, and Boolean as
well as enumerated, subrange, shortint, longint, bit16, bit32, and bit52 
types.

Syntax 

     Simple_type:

[]
Ordinal Ordinal types are types that have a one-to-one correspondence with a subset of natural numbers. These values are ordered so that each has a unique ordinal value that indicates its position in a list of all the values of the type. Ordinal types include bit16, bit32, bit52, Boolean, char, enumerated, integer, shortint, longint, and subrange. Enumerated types are declared by enumerating all the possible values of the type. Subrange types are declared by specifying the minimum and maximum values of the subrange. Integral-types include bit16, bit32, bit52, integer, shortint, longint, and subrange of integer. Sub-integer includes bit16, shortint, and subrange of integer; super-integer includes bit52 and longint. bit32 is a sub-integer when used with a real operand or used in a real function such as sin; otherwise, bit32 is a super-integer. Syntax Ordinal_type:
[]

NOTE For relational tests, the two operands must be compatible types. When membership tests are performed, the left-operand type must be a single ordinal value, while the right-operand is of a SET type.
Bit16. The predefined data type bit16 is a subrange, 0..65535, that is stored in 16 bits. bit16 is a unique HP Pascal type because arithmetic operations on bit16 data are truncated to modulo 65536 when stored. Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN arithmetic +, -, *, /, DIV, MOD Standard Functions bit16 argument - abs ln sin arctan odd sqr chr ord sqrt cos pred succ exp bit16 return - pred succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example program bits1 (output); var q:bit16; begin q:=hex('ffff'); q:=q + 1; { q is now 0 } writeln('wrapped around value = ',q:1); end. Output: wrapped around value = 0 Bit32. The predefined data type bit32 is a subrange, 0..232-1, that is stored in 32 bits. bit32 is a unique HP Pascal type because arithmetic operations on bit32 data are performed with unsigned 32 bit integers. Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN arithmetic +, -, *, /, DIV, MOD Standard Functions bit32 argument - abs ln sin arctan odd sqr chr ord sqrt cos pred succ exp bit32 return - pred sqr succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln
NOTE The multiply operator (*) may cause overflow traps. See "OVFLCHECK" .
Example $standard_level 'hp_modcal'$ program bits2(output); var q,r:bit32; begin { one way to get bit32 constants >= 2 ** 31 } $push; type_coercion 'conversion'; range off$ q:=bit32(hex('ffffffff')) + 1; { q is now 0 } r:=bit32(hex('7fffffff')) + 1; { r is now > maxint } $pop$ writeln('wrapped around value = ',q:1); writeln('past maxint value = ',r:1); end. Output: wrapped around value = 0 past maxint value = 2147483648 Bit52. The predefined data type bit52 is a subrange, 0..252-1, that is stored in 64 bits. bit52 is a unique HP Pascal type because arithmetic operations on bit52 data are performed with unsigned 64 bit integers. Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN arithmetic +, -, *, /, DIV, MOD Standard Functions bit52 argument - abs ln sin arctan odd sqr chr ord sqrt cos pred succ exp bit52 return - pred sqr succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example $standard_level 'hp_modcal'$ program bits3(output); var q:bit52; begin { one way to get bit52 constants >= 2 ** 31 } $push; type_coercion 'conversion'$ q:=bit52(123456) * 1000000000 + 789012345; $pop$ writeln(q); end. Output: 123456789012345 Boolean. The Boolean type is a predefined enumerated type that indicates logical values. The elements of this data type are two constant identifiers, true and false, where false is less than true. HP Pascal defines the type Boolean in the following way: TYPE Boolean = (false, true); Permissible Operators assignment := Boolean AND, OR, NOT relational <, <=, =, <>, >=, >, IN Standard Functions Boolean argument - ord pred succ Boolean return - eof eoln odd pred succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example VAR left_handed: Boolean; BEGIN left_handed := false; END; Char. The char type is a predefined ordinal type that is used to represent individual characters in the 8-bit ASCII character set. A char literal is either a single character surrounded by single quote marks, or a sharp (#) followed by a number or letter. Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN Standard Functions char argument - ord pred succ char return - chr pred succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example VAR do_you: char; BEGIN do_you := 'Y'; do_you := #G; { BELL character } END; Enumerated. An enumerated type is a user-defined, ordinal type that defines an ordered set of values by the enumeration of identifiers in parentheses. The sequence in which the identifiers appear determines the ordering. The enumerated identifiers are defined as constants. The ORD of the first has the value zero, and the ORD of the others have successive integer values in order of their specification. The limit on the maximum number of identifiers in an enumerated type is implementation dependent. Refer to the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation, for more information. Syntax Enumerated_id_list:
[]
Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN Standard Functions enumerated argument - ord pred succ enumerated return - pred succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example TYPE days = (monday, tuesday, wednesday, thursday, friday, saturday, sunday); color = (red, green, blue, yellow, cyan, magenta, white, black); Integer. The integer type is a predefined, ordinal type whose possible values are determined by a subrange of the negative and positive integers. The lower bound of the subrange is the predefined constant minint, and the upper bound is the predefined constant maxint. The integer type represents a signed number of at least nine digits. Permissible Operators assignment := relational <, <=, =, <>, >, >=, IN arithmetic +, -, *, /, DIV, MOD Standard Functions integer argument abs exp pred - arctan ln sin chr odd sqr cos ord succ integer return - abs maxpos round strmax binary octal sqr strpos hex ord sqrt succ lastpos position strlen trunc linepos pred Standard Procedures halt strread prompt strwrite read writedir readdir writeln readln Example VAR wholenum: integer; i,j,k,l : integer; Longint. The predefined data type longint is an integer in the range -263..263-1 that is stored in 64 bits. Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN arithmetic +, -, *, /, DIV, MOD Standard Functions longint argument abs ln sin - arctan odd sqr chr ord sqrt cos pred succ exp longint return - abs pred sqr succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example $standard_level 'hp_modcal'$ program prog(output); var q:longint; begin { one way to get longint constants >= 2 ** 31 or < - 2 ** 31 } $push; type_coercion 'conversion'$ q:=longint(123456) * 1000000000 + 789012345; $pop$ writeln(q); end. Output: 123456789012345 Shortint. The predefined data type shortint is an integer in the range -32768..32767 that is stored in 16 bits. (In contrast, if you declare a variable to be in that range, it is stored in 32 bits.) Permissible Operators assignment := relational <, <=, =, <>, >=, >, IN arithmetic +, -, *, /, DIV, MOD Standard Functions shortint argument - abs ln sin arctan odd sqr chr ord sqrt cos pred succ exp shortint return - pred succ Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example program short(output); var q:shortint; begin q:=-1; writeln('size of shortint = ',sizeof(q):1); end. Output: size of shortint = 2 Subrange. A subrange type is a user-defined, ordinal type that is a sequential subset of a predefined or user-defined, ordinal base type. It consists of a lower bound and an upper bound separated by the special symbol "..". The upper and lower bounds must be constant values or constant expressions of the same ordinal type. The lower bound cannot be greater than the upper bound. Syntax Subrange_type:
[]

NOTE A variable of a subrange type possesses all the attributes of the base type of the subrange, but its values are restricted to the specified closed range. It has the same set of permissible operators and standard functions as its base type.
Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example CONST maxsize = 10; TYPE day_of_year = 1..366; lowercase = 'a'..'z'; { Base type is char. } days = (Monday, Tuesday, Wednesday, Thursday,Friday,Saturday,Sunday); weekdays = Monday..Friday; weekend = Saturday..Sunday; e_type = 1..maxsize - 1; { Upper bound is con- } { stant expression. } { Maxsize is declared } { constant. } Real The real type is a predefined, simple type that represents a subset of the real numbers. For the range covered by the subset, see the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation. Permissible Operators assignment := relational <, <=, =, <>, >=, > arithmetic -, +, *, / Standard Functions real argument - abs ln sqr arctan round sqrt cos sin trunc exp real return - abs exp sqr arctan ln sqrt cos sin Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example PROGRAM show_realnum(output); VAR realnum: real; BEGIN realnum := 6.023E+23; writeln(realnum); END. Output: 6.02300E+23 Longreal The longreal type is a predefined, simple type that represents a subset of the real numbers. This type may have more precision and a larger range than the type real. The range the subset covers is implementation dependent in HP Pascal. For more details see the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation. Permissible Operators assignment := relational <, <=, =, <>, >=, > arithmetic -, +, *, / Standard Functions longreal argument - abs round arctan sin cos sqr exp sqrt ln trunc longreal return - abs ln arctan sin cos sqr exp sqrt Standard Procedures prompt strread read strwrite readdir writedir readln writeln Example VAR precisenum: longreal; BEGIN precisenum:= 1.1234567891L+04; .


MPE/iX 5.0 Documentation