Constants
The data type of a constant is determined by its syntax, as explained later in this section. In PV-WAVE there are nine basic data types, each with its own form of constant:
BYTE—8-bit unsigned integers.
INT—16-bit signed integers.
INT32—32-bit signed integers.
LONG—A 32-bit (or 64-bit in 64-bit PV-WAVE) signed integer.
FLOAT—32-bit single-precision floating-point.
DOUBLE—64-bit double-precision floating-point.
COMPLEX—Real-imaginary pair using single-precision floating-point.
DCOMPLEX—Real-imaginary pair using double-precision floating-point.
STRING—Zero or more eight-bit characters which are interpreted as text.
In addition, structures, lists, and associative arrays are defined in terms of the nine basic data types.
Working with Structures describes the use of structures in detail.
Numeric Constants
This section discusses the different kinds of numeric constants in PV‑WAVE and their syntax. The types of numeric constants are:
Integer constants.
Floating-point and double-precision constants.
Complex constants.
Integer Constants
Numeric constants of different types may be represented by a variety of forms. The syntax of integer constants is shown in the following table, where “n” represents one or more digits.
Digits in hexadecimal constants may include the letters A through F, for the decimal numbers 10 through 15. Also, octal constants may be written using the same style as hexadecimal constants by substituting an O for the X. The following table illustrates both examples of valid and invalid constants.
Values of integer constants can range from 0 to 255 for BYTEs, 0 to ± 32,767 for INTs, 0 to ± 231 –1 for INT32s, and 0 to ± 231 –1 (on 32-bit systems) or 0 to ± 263 –1 (on 64-bit systems) for LONGs. Integers that are initialized with absolute values greater than 32,767 are automatically typed as longword. Any numeric constant may be preceded by a + or a – sign. To ensure cross-platform compatibility, place the + or a – sign outside of the apostrophe.
note | To maintain backwards compatibility, INT variables do not get promoted to INT32s, only to LONGs. In addition, INT32 variables do not get promoted when they are initialized to absolute values larger than 232. |
There is no checking for integer overflow conditions when performing integer arithmetic. For example, the statement:
print, 32767 + 10
will give an incorrect answer and no error message. For more details on overflow conditions and error checking, see
Programming with PV-WAVE.
Floating-point and Double-precision Constants
Floating-point and double-precision constants may be expressed in conventional or scientific notation. Any numeric constant that includes the decimal point is a floating-point or double-precision constant.
The notation sx represents the sign and magnitude of the exponent, for example: E-2.
Double-precision constants are entered in the same manner, replacing E with a D. For example, 1.0D0, 1D, 1.D, all represent a double precision one.
Complex Constants
Complex constants contain a real and an imaginary part, which can be of single or double-precision floating point numbers. The imaginary part may be omitted, in which case it is assumed to be zero.
The form of a complex constant is:
COMPLEX(real_part, imaginary_part)
or:
COMPLEX(real_part)
For example, COMPLEX(1, 2), is a complex constant with a real part of one, and an imaginary part of two. COMPLEX(1)is a complex constant with a real part of one and a zero imaginary component.
The ABS function returns the magnitude of a complex expression. To extract the real part of a complex expression, use the FLOAT function; to extract the imaginary part, use the IMAGINARY function. These functions are explained in the PV‑WAVE Reference.
Type Promotion
When a binary operation is performed on operands of different numeric type, the lower type is promoted to the higher type prior to the operation.
String Constants
A string constant consists of zero or more characters enclosed by apostrophes ( ' ) or quotation marks ( " ). The value of the constant is simply the characters appearing between the leading delimiter ( ' or " ) and the next occurrence of the delimiter.
A double apostrophe ( ' ' ) or double quotation mark ( " " ) is considered to be the null string; a string containing no characters.
An apostrophe or quotation mark may be represented within a string that is delimited by the same character, by two apostrophes, or quotation marks.
For example, 'Don''t' produces Don't; or you can write: "Don't" to produce the same result.
Examples of Correct String Constants illustrates valid string constants.
Examples of Incorrect String Constants illustrates invalid string constants.
note | The entry "129" is interpreted as an illegal octal constant. This is because a quotation mark character followed by a digit from 0 to 7 represents an octal numeric constant, not a string, and the character 9 is an illegal octal digit. |
Representing Nonprintable Characters with UNIX
The ASCII characters with values less than 32 or greater than 126 do not have printable representations. Such characters are included in string constants by specifying their octal or hexadecimal values. A character is specified in octal notation as a backslash followed by its three-digit octal value, and in hex as a backslash followed by the
x or
X character, followed by its two-digit hexadecimal value. In order to construct a character string which actually contains a literal backslash character, it is necessary to enter two consecutive backslash characters. For example,
'C:\data\070197.dat' will not generate the expected filename. Use
'C:\\data\\070197.dat' instead.
Specifying Non-printing Characters gives examples of using octal or hexadecimal character notation.
Representing Nonprintable Characters with Windows
The ASCII characters with values less than 32 or greater than 126 do not have printable representations. To include such “nonprintable” characters in a string, you can use the STRING function. For example, the bell sound is a nonprintable ASCII “character”. The way to represent this character in a string is:
s='This is a bell:' + STRING(7B)
PRINT, s
; The text is printed and the bell rings.
The notation “7B” indicates that the parameter is of byte data type. The result is equal to the decimal ASCII code 7, which is the bell character. For more information, see
"Using STRING with Byte Arguments".
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.