Constants
The data type of a constant is determined by its syntax, as explained later in this section. In PV-WAVE there are
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 singl
DOUBLE—64-bit double-precision
COMPLEX—Real-imaginary pair using
DCOMPLEX—Real-imaginary pair using
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
Radix | Type | Form | Examples |
---|---|---|---|
Decimal | BYTE | nB |
12B, 34B |
INT | n | 12, 425 |
|
INT32 | nI |
12I, 94I |
|
LONG | nL |
12L, 94L |
|
Hexadecimal | BYTE | 'n'XB |
'2E'XB |
INT | 'n'X |
'0F'X |
|
INT32 | 'n'XI |
'FF'XI |
|
LONG | 'n'XL |
'FF'XL |
|
Octal | BYTE | "nB |
"12B |
INT | "n | "12 |
|
'n'O |
'377'O |
||
INT32 | "nI |
"12I |
|
'n'OI |
'777777'OI |
||
LONG | "nL |
"12L |
|
'n'OL |
'777777'OL |
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.
Correct | Incorrect | Reason |
---|---|---|
255
|
256B
|
Too large, limit is 255 |
'123'X
|
'123X
|
Unbalanced apostrophe |
-'123'X
|
'-123'X
|
Minus sign inside apostrophe |
"123
|
'03G'x
|
Invalid character |
'27'OL
|
'27'L
|
No radix |
'650'XL
|
650XL
|
No apostrophes |
"124
|
"129
|
9 is an invalid octal digit |
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.
There is no checking for integer overflow
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
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.
Form | Example |
---|---|
n . | 102. |
. n | .102 |
n .n | 10.2 |
n Esx | 10E5 |
n .Esx | 10.E–3 |
.n Esx | .1E+12 |
n .n Esx | 2.3E12 |
Complex Constants
The form of a complex constant is:
COMPLEX(real_part, imaginary_part)
or:
COMPLEX(real_part)
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.
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.
Type | Description |
---|---|
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 Constants
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.
String Value | Correct |
---|---|
Hi there | 'Hi there'
|
Hi there | "Hi there"
|
Null String | ' '
|
I’m happy | "I'm happy"
|
I’m happy | 'I''m happy'
|
counter | 'counter'
|
129 | '129'
|
Examples of Incorrect String Constants illustrates invalid string constants.
String Value | Incorrect | Reason |
---|---|---|
Hi there | 'Hi there"
|
Mismatched delimiters |
Null String | '
|
Missing delimiter |
I’m happy | 'I'm happy'
|
Apostrophe in string |
counter | ''counter''
|
Double apostrophe is null string |
129 | "129"
|
Illegal octal constant |
"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
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.
Specified String | Actual Contents | Comment |
---|---|---|
'\033[;H\033[2J'
|
'<Esc>[;H<Esc>[2J' | Erase—ANSI terminal |
'\x1B[;H\X1b[2J'
|
'<Esc>[;H<Esc>[2J' | Erase—hex notation |
'\007'
|
Bell | Ring the bell |
'\x08'
|
Backspace | Move cursor left |
'\014'
|
Formfeed | Eject current page |
'\\hello'
|
'\hello' | Literal backslash |
Representing Nonprintable Characters with Windows
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.