# float

The keyword float denotes a simple basic type describing floating point numbers.

- Values of float type shall be denoted by either
  - the normal notation with a dot in a sequence of numbers, or
  - by two numbers separated by E where the first number specifies the mantissa and the second specifies the exponent (the base is always 10).
- The range of the permitted floating point values may be specified.
- The specified range may be infinite (both positive and negative; see the keyword infinity).
- Another way to limit the permitted float values is to list them.
- Value list and value range restrictions may be combined
- A random floating point number may be generated using the predefined function rnd().
- Predefined function operating on floating point numbers:

- float2int converts a floating point number into an integer value.

TITAN specific extension to the standard:

- float2str converts a floating point value to a character string.

Related keyword:

- float2int
- float2str
- infinity
- int2float
- rnd
- str2float

### float

Example 1:

var float v_lebeg := 65.213;

The variable defined is called v_lebeg and has the initial value 65.213 (with scientific notation 6.5213E1).

Example 2:

var float v_flotte := 6521.3E-2;

The variable defined is called v_flotte and has the initial value 6521.3E-2 (with normal notation 65.213).

Example 2:

var float v_territoire (3.3 .. 7.7);

The variable v_territoire may have values between 3.3 and 7.7 inclusive.

Example 3:

var float v_kado (1.2, 5E9, -12);

The variable called v_kado may hold the values 1.2, 5E9 and -12 only .

Example 4:

var float v_kenyeer ( 1.9, 7.000 .. 7.999, 11.1E1 );

The variable v_kenyeer may hold the values 1.9, 111 and any value between 7.000 and 7.999 inclusive.

Example 5:

var float v_veeletlen := rnd ( 1.9 );

The variable v_veeletlen will have a random initial value between 0 and 1. The argument of the function is an optional seed value used for the first time random value calculation. If it is omitted, the system time will be used as seed.

Example 6:

const integer c_tam := float2int (344.511E-2);

The constant called c_tam will have the integer value 3 (the function calculates the integer value by removing the fractional part of the argument).

Example 7:

const bitstring c_recefice := float2str (3.14);

The constant called c_recefice will contain the character string "3.140000" because if the input is zero or its absolute value is between 10-4 and 1010 the decimal dot notation is used in the output with 6 digits in the fraction part. Otherwise the exponential notation is used with automatic (at most 6) digits precision in the mantissa.

BNF definition of float
BNF definition of float value