Arithmetic Functions Summary
PowerBASIC provides a reasonably complete set of arithmetic functions, which can be broken into the following categories. As you can see from the examples below, use of the functions is very simple and mostly self-explanatory.

E Notation
PowerBASIC allows number to be written using E notation for powers of 10. "E", "e", "D", or "d" may be used at the separator between the coefficient number and the exponent of ten. The E/e refers to raising the coefficient to the power of 10, not the mathematical constant e.

The use of E was popularized by the need for an easy way to express large and small numbers on calculators and computers, where 2.4E2 is easier to write than 2.4 x 10^2.

Numeric Conversion Between Types
In assignments and when passing parameter, PowerBASIC automatically converts a numeric values to the numeric type required, as in the following example.

    i% = a!     'single precision a! is converted to integer
    c& = f@     'currency type is converted to long integer

However, PowerBASIC also provides a series of functions which can explicitly make these conversions. These are rarely used since PowerBASIC makes the conversions automatically. The conversion functions are:

    CBYT    CDBL    CINT    CSNG
    CCUR    CDWB    CLNG    CWRD
    CCUX    CEXT    CQUD

    i% = CINT(a!)  'same result as  i%=a!

These functions should be self-explanatory as to the data type each returns. However, note that with the CINT/CLNG functions, when the fractional part of the number is exactly 0.5, the number is rounded to the nearest even number. This means a number ending in .5 may round up or down - not always up!

    CINT(0.5)    'returns 0, not 1  (nearest EVEN number)
    CINT(1.5)    'returns 2 (nearest EVEN number)
    CINT(2.5)    'returns 2, not 3
    CLNG(-4.7)   'returns -5
    CLNG(7.7)    'returns 7

Note that while PowerBASIC will automatically convert between numeric data types, it will not automatically convert numeric values to strings. This has to be explicitly done by the program code.

Clarification of Integer Functions
The PowerBASIC functions dealing with integer - CINT, INT, FIX, CEIL, ROUND, CVI, and MKI$ - may seem obvious in their usage, but there are some nuances. Here are comparisons on how these functions round various numbers, including negative numbers. See specific examples further down this page.

BIN$ / HEX$ / OCT$ Functions
PowerBASIC can work with numbers in other than base 10. In particular, it supports base 2, 8, and 16. Numbers in bases other than 10 are written with one of the following prefixes. Numbers in base 10 are referred to a decimal values. Here's the notation to use for describing numbers of other bases. Note that PowerBASIC supports 3 ways to represent octal notation.

    &B  - binary
    &O  - octal (that's letter O, not number zero 0)
    &Q  - octal  &Q7
    &   - octal  &7
    &H  - hexadecimal

    A = &H0F    'hex value of "0F" (decimal 15)
    B = &Q7     'octal value of "7" (decimal 7)
    C = &B11    'binary value of "11" (decimal 3)

To convert numeric values to strings, PowerBASIC supplies the BIN$, OCT$, and HEX$ functions. These three functions take a numeric value and return the binary (base 2), octagonal (base 8), or hexadecimal (base 16) value as a string.

To convert base 2/8/16 strings to numeric (base 10) numbers, use the VAL function. It recognizes the following base number string prefixes.

Arithmetic Functions Listing
Here are one-line descriptions of all the arithmetic functions.

Arithmetic Functions Examples
Here are examples for each of the arithmetic functions. The functions are listed in alphabetical order.

If you have any suggestions or corrections, please let me know.