Skip to main content

Math

Struct Math 

Source
pub struct Math {
    pub errno: bool,
    pub finite_only: bool,
    pub signed_zeros: bool,
    pub reciprocal: bool,
    pub associative: bool,
    pub unsafe_math: bool,
}
Expand description

The members of -ffast-math that are licences about what an arithmetic may answer, one field each, so that a build writing -ffast-math -fno-finite-math-only gets what gcc gives it.

Nothing here folds floating point arithmetic in a function body at any level, so none of these changes the code this compiler writes. What each one does change is the predefined set: gcc names each licence it was given with a macro of its own, <math.h> and a numerics library read those, and a header that configured itself for a licence the other objects were built without is a program answering two ways. -ftrapping-math is the sixth member and lives in Options::trapping_math, because it was taken before the rest and it is the one that does change an answer here.

Fields§

§errno: bool

Whether a function in the maths library is taken to set errno, from -fmath-errno. On, which is gcc’s default on a target whose library does it.

§finite_only: bool

Whether the program promises there are no NaNs and no infinities, from -ffinite-math-only.

§signed_zeros: bool

Whether the sign of a zero is kept, from -fsigned-zeros. On by default.

§reciprocal: bool

Whether a division may become a multiplication by the reciprocal, from -freciprocal-math.

§associative: bool

Whether an addition may be regrouped, from -fassociative-math. gcc drops this with a warning unless signed zeros and trapping are both off, so what counts is Math::associative rather than the field.

§unsafe_math: bool

-funsafe-math-optimizations, which is its own flag as well as the three it turns on.

Implementations§

Source§

impl Math

Source

pub fn set_unsafe(&mut self, on: bool) -> bool

-funsafe-math-optimizations and its negative, which set or clear the members gcc’s set_unsafe_math_optimizations_flags does. Trapping is one of them, so it is handed back for the caller to store where it lives.

Source

pub fn set_fast(&mut self, on: bool) -> bool

-ffast-math and -fno-fast-math, which are set_fast_math_flags in gcc: the unsafe group, the maths library’s errno and the promise about NaNs. The value handed back is trapping, as above.

Source

pub fn associative(&self, trapping: bool) -> bool

Whether regrouping survives, which it does only where nothing could tell: a regrouped sum can move a zero’s sign and can raise an exception the original order did not.

Source

pub fn fast(&self, trapping: bool) -> bool

Whether every member is in the permissive position, which is what __FAST_MATH__ says. Written out rather than remembered from the flag, because -ffast-math -ftrapping-math is not fast math and gcc does not define the macro for it.

Source

pub fn iec_559(&self, trapping: bool) -> bool

Whether the arithmetic is still IEC 60559’s, which is what __GCC_IEC_559 answers and what glibc writes __STDC_IEC_559__ from. Any of these licences is an answer the standard does not give.

Trait Implementations§

Source§

impl Clone for Math

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Math

Source§

impl Debug for Math

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Math

Source§

fn default() -> Math

Returns the “default value” for a type. Read more
Source§

impl Eq for Math

Source§

impl Hash for Math

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Math

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Math

Auto Trait Implementations§

§

impl Freeze for Math

§

impl RefUnwindSafe for Math

§

impl Send for Math

§

impl Sync for Math

§

impl Unpin for Math

§

impl UnsafeUnpin for Math

§

impl UnwindSafe for Math

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.