Data types: float
Represents a floating-point number with single-precision.
Type syntax
float
Literal syntax
+/-decimal‑literal.decimal‑fraction
Discussion
The floating-point numbers must always be expressed in the decimal-point notation with an optional + or - sign put in front of the number. 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;
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).
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. |