Programmer Guide > Constants and Variables > Constants
  

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.
 
Table 2-1: Syntax of 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.
 
Table 2-2: Examples of Integer 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.
 
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.
 
Table 2-3: Syntax of Floating-point Constants  
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
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.
 
Table 2-4: Hierarchy of Numeric Types from Lowest to Highest
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 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.
 
Table 2-5: Examples of Correct 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.
 
Table 2-6: Examples of Incorrect 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
 
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.
 
Table 2-7: Specifying Non-printing Characters  
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
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.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.