Data types: float

Represents a floating-point number with single-precision.

Type syntax

float

Literal syntax

+/-decimal‑literal.decimal‑literale+/-decimal‑literal

Discussion

The floating-point numbers are expressed in the decimal-point notation with an optional + or - sign put in front of the number and an optional exponent after a trailing e. The literals can be used within expressions wherever a float operand is expected. The type name float, in turn, is designated to be used in declarations of data members. For example:

var float angle   =  90.0;
var float voltage = -5.13;
var float current =  1.3e-3;

Floating point precision

Generally, the programming language Chora assumes the float data type and the associated operations as being performed with at least 32-bit single precision. This may differ on target systems supporting the floating-point data type with double precision (64-bit).

Instant properties

With the following instant properties you can evaluate status or the value of a float operand:

Instant property name

Short description

abs

Represents the absolute value of the given float operand.

ceil

Represents the next highest integer value of a float operand.

floor

Represents the next lowest integer value of a float operand.

fract

Represents the fractional part of a float operand.

isinf

Verifies the Infinity (+INF or -INF) status of a float operand.

isinfn

Verifies the Negative Infinity (-INF) status of a float operand.

isinfp

Verifies the Positive Infinity (+INF) status of a float operand.

isnan

Verifies the Not a Number (NAN) status of a float operand.

round

Represents the float operand rounded to the next lowest or highest integer value.

trunc

Represents the float operand rounded by removing the fractional part.

Arithmetic operations

You can combine a float operand with other operands to arithmetic expressions. The following table provides an overview of the possible operations:

Operator

Short description

+

Addition

-

Subtraction

*

Multiplication

/

Division

Comparison operations

You can compare two float operands in order to test whether these are equal or not. The following table provides an overview of the possible operations:

Operator

Short description

==

Equality

!=

Inequality

<

Less than

>

Greater than

<=

Less than or equal

>=

Greater than or equal

Type conversions

Chora reacts sensitive when mixing operands of different data types within an operation. To avoid compiler warnings or even errors you can convert the affected operands explicitly by using following conversion operations:

Conversion operations with signed integers

Conversion to or from a signed or unsigned integer value.

Formatting a string from a floating-point number.

Parsing a string as a floating-point number.