glam_det 2.0.0

A simple and fast 3D math library for games and graphics.
Documentation
// Copyright (C) 2020-2025 glam-det authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::num_traits::*;

impl Num for f32 {
    type Element = f32;
    type Bool = bool;

    #[inline]
    fn lanes() -> usize {
        1
    }
    #[inline]
    fn splat(val: Self::Element) -> Self {
        val
    }
    #[inline]
    fn extract(&self, _i: usize) -> Self::Element {
        *self
    }
    #[inline]
    unsafe fn extract_unchecked(&self, _i: usize) -> Self::Element {
        *self
    }
    #[inline]
    fn replace(&mut self, _i: usize, val: Self::Element) {
        *self = val
    }
    #[inline]
    unsafe fn replace_unchecked(&mut self, _i: usize, val: Self::Element) {
        *self = val
    }
    #[inline]
    fn select(self, cond: Self::Bool, other: Self) -> Self {
        if cond {
            self
        } else {
            other
        }
    }
}

#[cfg(any(
    feature = "libm_force",
    all(feature = "libm_fallback", not(feature = "std"))
))]
impl Signed for f32 {
    #[inline]
    fn absf(self) -> Self {
        libm::fabsf(self)
    }
    #[inline]
    fn signumf(self) -> Self {
        if self.is_nan() {
            Self::NAN
        } else {
            libm::copysignf(1.0_f32, self)
        }
    }
}

#[cfg(any(
    feature = "libm_force",
    all(feature = "libm_fallback", not(feature = "std"))
))]
impl Float for f32 {
    #[inline]
    fn asinf(self) -> Self {
        libm::asinf(self)
    }
    #[inline]
    fn acosf(self) -> Self {
        libm::acosf(self)
    }
    #[inline]
    fn atanf(self) -> Self {
        libm::atanf(self)
    }
    #[inline]
    fn atan2f(self, x: Self) -> Self {
        libm::atan2f(self, x)
    }
    #[inline]
    fn ceilf(self) -> Self {
        libm::ceilf(self)
    }
    #[inline]
    fn copysignf(self, sign: Self) -> Self {
        libm::copysignf(self, sign)
    }
    #[inline]
    fn expf(self) -> Self {
        libm::expf(self)
    }
    #[inline]
    fn floorf(self) -> Self {
        libm::floorf(self)
    }
    #[inline]
    fn is_finite(self) -> Self::Bool {
        f32::is_finite(self)
    }
    #[inline]
    fn is_nan(self) -> Self::Bool {
        f32::is_nan(self)
    }
    #[inline]
    fn mul_addf(self, b: Self, c: Self) -> Self {
        libm::fmaf(self, b, c)
    }
    #[inline]
    fn powif(self, n: i32) -> Self {
        libm::powf(self, n as f32)
    }
    #[inline]
    fn powff(self, n: Self) -> Self {
        libm::powf(self, n)
    }
    #[inline]
    fn recip(self) -> Self {
        f32::recip(self)
    }
    #[inline]
    fn roundf(self) -> Self {
        libm::roundf(self)
    }
    #[inline]
    fn sqrtf(self) -> Self {
        libm::sqrtf(self)
    }
    #[inline]
    fn sinf(self) -> Self {
        libm::sinf(self)
    }
    #[inline]
    fn cosf(self) -> Self {
        libm::cosf(self)
    }
    #[inline]
    fn sin_cosf(self) -> (Self, Self) {
        libm::sincosf(self)
    }
    #[inline]
    fn tanf(self) -> Self {
        libm::tanf(self)
    }
    #[inline]
    fn minf(self, other: Self) -> Self {
        libm::fminf(self, other)
    }
    #[inline]
    fn maxf(self, other: Self) -> Self {
        libm::fmaxf(self, other)
    }
}

#[cfg(all(feature = "std", not(feature = "libm_force")))]
impl Float for f32 {
    #[inline]
    fn asinf(self) -> Self {
        f32::asin(self)
    }
    #[inline]
    fn acosf(self) -> Self {
        f32::acos(self)
    }
    #[inline]
    fn atanf(self) -> Self {
        f32::atan(self)
    }
    #[inline]
    fn atan2f(self, x: Self) -> Self {
        f32::atan2(self, x)
    }
    #[inline]
    fn ceilf(self) -> Self {
        f32::ceil(self)
    }
    #[inline]
    fn copysignf(self, sign: Self) -> Self {
        f32::copysign(self, sign)
    }
    #[inline]
    fn expf(self) -> Self {
        f32::exp(self)
    }
    #[inline]
    fn floorf(self) -> Self {
        f32::floor(self)
    }
    #[inline]
    fn is_finite(self) -> Self::Bool {
        f32::is_finite(self)
    }
    #[inline]
    fn is_nan(self) -> Self::Bool {
        f32::is_nan(self)
    }
    #[inline]
    fn mul_addf(self, b: Self, c: Self) -> Self {
        f32::mul_add(self, b, c)
    }
    #[inline]
    fn powif(self, n: i32) -> Self {
        f32::powi(self, n)
    }
    #[inline]
    fn powff(self, n: Self) -> Self {
        f32::powf(self, n)
    }
    #[inline]
    fn recip(self) -> Self {
        f32::recip(self)
    }
    #[inline]
    fn roundf(self) -> Self {
        f32::round(self)
    }
    #[inline]
    fn sqrtf(self) -> Self {
        f32::sqrt(self)
    }
    #[inline]
    fn sinf(self) -> Self {
        f32::sin(self)
    }
    #[inline]
    fn cosf(self) -> Self {
        f32::cos(self)
    }
    #[inline]
    fn sin_cosf(self) -> (Self, Self) {
        f32::sin_cos(self)
    }
    #[inline]
    fn tanf(self) -> Self {
        f32::tan(self)
    }
    #[inline]
    fn minf(self, other: Self) -> Self {
        f32::min(self, other)
    }
    #[inline]
    fn maxf(self, other: Self) -> Self {
        f32::max(self, other)
    }
}

#[cfg(all(feature = "std", not(feature = "libm_force")))]
impl Signed for f32 {
    #[inline]
    fn absf(self) -> Self {
        f32::abs(self)
    }
    #[inline]
    fn signumf(self) -> Self {
        f32::signum(self)
    }
}