1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use enumset::{EnumSet, EnumSetType};
use serde::{Deserialize, Serialize};
/// Unchecked optimizations for float operations. May cause precision differences, or undefined
/// behaviour if the relevant conditions are not followed.
#[derive(Default, Debug, Hash, Serialize, Deserialize, EnumSetType)]
pub enum FastMath {
/// Disable unsafe optimizations
#[default]
None,
/// Assume values are never `NaN`. If they are, the result is considered undefined behaviour.
NotNaN,
/// Assume values are never `Inf`/`-Inf`. If they are, the result is considered undefined
/// behaviour.
NotInf,
/// Ignore sign on zero values.
UnsignedZero,
/// Allow swapping float division with a reciprocal, even if that swap would change precision.
AllowReciprocal,
/// Allow contracting float operations into fewer operations, even if the precision could
/// change.
AllowContraction,
/// Allow reassociation for float operations, even if the precision could change.
AllowReassociation,
/// Allow all mathematical transformations for float operations, including contraction and
/// reassociation, even if the precision could change.
AllowTransform,
/// Allow using lower precision intrinsics (CUDA `--use_fast_math`)
/// Also impacts `NaN`, `Inf` and signed zero handling, as well as subnormals and rounding.
///
/// Notable edge case:
/// powf - Returns `NaN` for negative bases
ReducedPrecision,
}
impl FastMath {
pub fn all() -> EnumSet<FastMath> {
EnumSet::all()
}
}