Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The Floating-Point Types are available in 32-bit (f32) and 64-bit (f64) versions.

Table 1 presents the available floating-point operators.

Table 1:Floating-point operators

Operator

Description

+

Addition

-

Subtraction

*

Multiplication

/

Division

%

Remainder

6.2.1Default type

The default type for floats is f64:

10.0

6.2.2Specifying the type

As for integers, the type can be set either to the variable or the value:

(3.0, 3.0)

6.2.3Operations

Example of computing a remainder:

2.1600000000000015

A division:

9.6

Many useful constants are directly accessible on the primitive type f64 or f32.

For 32-bit float numbers:

Number of significant digits: 6
Maximum: 3.40e38
Minimum: -3.40e38
NaN: NaN
Infinity: inf
Negative infinity: -inf
ε: 1.19e-7

For 64-bit float numbers:

Number of significant digits: 15
Maximum: 1.80e308
Minimum: -1.80e308
NaN: NaN
Infinity: inf
Negative infinity: -inf
ε: 2.22e-16

6.2.5Mathematical constants

Multiple useful mathematical float constants can be found in std::f32::consts and std::f64::consts.

Here are some examples of constants for the 32-bit float type:

e=2.7182817
π=3.1415927
1/π=0.31830987
φ=1.618034