Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Mark generic functions #[inline] #545

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/math/fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn fmaf128(x: f128, y: f128, z: f128) -> f128 {

/// Fused multiply-add that works when there is not a larger float size available. Computes
/// `(x * y) + z`.
#[inline]
pub fn fma_round<F>(x: F, y: F, z: F, _round: Round) -> FpResult<F>
where
F: Float,
Expand Down
1 change: 1 addition & 0 deletions src/math/fma_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn fmaf(x: f32, y: f32, z: f32) -> f32 {

/// Fma implementation when a hardware-backed larger float type is available. For `f32` and `f64`,
/// `f64` has enough precision to represent the `f32` in its entirety, except for double rounding.
#[inline]
pub fn fma_wide_round<F, B>(x: F, y: F, z: F, round: Round) -> FpResult<F>
where
F: Float + HFloat<D = B>,
Expand Down
2 changes: 2 additions & 0 deletions src/math/generic/ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use super::super::support::{FpResult, Status};
use super::super::{Float, Int, IntTy, MinInt};

#[inline]
pub fn ceil<F: Float>(x: F) -> F {
ceil_status(x).val
}

#[inline]
pub fn ceil_status<F: Float>(x: F) -> FpResult<F> {
let zero = IntTy::<F>::ZERO;

Expand Down
1 change: 1 addition & 0 deletions src/math/generic/copysign.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::Float;

/// Copy the sign of `y` to `x`.
#[inline]
pub fn copysign<F: Float>(x: F, y: F) -> F {
let mut ux = x.to_bits();
let uy = y.to_bits();
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fabs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::Float;

/// Absolute value.
#[inline]
pub fn fabs<F: Float>(x: F) -> F {
let abs_mask = !F::SIGN_MASK;
F::from_bits(x.to_bits() & abs_mask)
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fdim.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::super::Float;

#[inline]
pub fn fdim<F: Float>(x: F, y: F) -> F {
if x <= y { F::ZERO } else { x - y }
}
2 changes: 2 additions & 0 deletions src/math/generic/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use super::super::support::{FpResult, Status};
use super::super::{Float, Int, IntTy, MinInt};

#[inline]
pub fn floor<F: Float>(x: F) -> F {
floor_status(x).val
}

#[inline]
pub fn floor_status<F: Float>(x: F) -> FpResult<F> {
let zero = IntTy::<F>::ZERO;

Expand Down
2 changes: 1 addition & 1 deletion src/math/generic/fmax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use super::super::Float;

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
#[inline]
pub fn fmax<F: Float>(x: F, y: F) -> F {
let res = if x.is_nan() || x < y { y } else { x };
// Canonicalize
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fmaximum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use super::super::Float;

#[inline]
pub fn fmaximum<F: Float>(x: F, y: F) -> F {
let res = if x.is_nan() {
x
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fmaximum_num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use super::super::Float;

#[inline]
pub fn fmaximum_num<F: Float>(x: F, y: F) -> F {
let res =
if x.is_nan() || x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fmin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use super::super::Float;

#[inline]
pub fn fmin<F: Float>(x: F, y: F) -> F {
let res = if y.is_nan() || x < y { x } else { y };
// Canonicalize
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fminimum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use super::super::Float;

#[inline]
pub fn fminimum<F: Float>(x: F, y: F) -> F {
let res = if x.is_nan() {
x
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/fminimum_num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use super::super::Float;

#[inline]
pub fn fminimum_num<F: Float>(x: F, y: F) -> F {
let res =
if y.is_nan() || x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
Expand Down
2 changes: 1 addition & 1 deletion src/math/generic/fmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use super::super::{CastFrom, Float, Int, MinInt};

#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
#[inline]
pub fn fmod<F: Float>(x: F, y: F) -> F {
let zero = F::Int::ZERO;
let one = F::Int::ONE;
Expand Down
3 changes: 3 additions & 0 deletions src/math/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Note: generic functions are marked `#[inline]` because, even though generic functions are
// typically inlined, this does not seem to always be the case.

mod ceil;
mod copysign;
mod fabs;
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/rint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::super::support::{FpResult, Round};

/// IEEE 754-2019 `roundToIntegralExact`, which respects rounding mode and raises inexact if
/// applicable.
#[inline]
pub fn rint_round<F: Float>(x: F, _round: Round) -> FpResult<F> {
let toint = F::ONE / F::EPSILON;
let e = x.ex();
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/round.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::{Float, MinInt};
use super::{copysign, trunc};

#[inline]
pub fn round<F: Float>(x: F) -> F {
let f0p5 = F::from_parts(false, F::EXP_BIAS - 1, F::Int::ZERO); // 0.5
let f0p25 = F::from_parts(false, F::EXP_BIAS - 2, F::Int::ZERO); // 0.25
Expand Down
1 change: 1 addition & 0 deletions src/math/generic/scalbn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use super::super::{CastFrom, CastInto, Float, IntTy, MinInt};
/// >
/// > If the calculation does not overflow or underflow, the returned value is exact and
/// > independent of the current rounding direction mode.
#[inline]
pub fn scalbn<F: Float>(mut x: F, mut n: i32) -> F
where
u32: CastInto<F::Int>,
Expand Down
2 changes: 2 additions & 0 deletions src/math/generic/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use super::super::support::{FpResult, IntTy, Round, Status, cold_path};
use super::super::{CastFrom, CastInto, DInt, Float, HInt, Int, MinInt};

#[inline]
pub fn sqrt<F>(x: F) -> F
where
F: Float + SqrtHelper,
Expand All @@ -57,6 +58,7 @@ where
sqrt_round(x, Round::Nearest).val
}

#[inline]
pub fn sqrt_round<F>(x: F, _round: Round) -> FpResult<F>
where
F: Float + SqrtHelper,
Expand Down
2 changes: 2 additions & 0 deletions src/math/generic/trunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
use super::super::support::{FpResult, Status};
use super::super::{Float, Int, IntTy, MinInt};

#[inline]
pub fn trunc<F: Float>(x: F) -> F {
trunc_status(x).val
}

#[inline]
pub fn trunc_status<F: Float>(x: F) -> FpResult<F> {
let mut xi: F::Int = x.to_bits();
let e: i32 = x.exp_unbiased();
Expand Down
1 change: 1 addition & 0 deletions src/math/roundeven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn roundevenf128(x: f128) -> f128 {
roundeven_impl(x)
}

#[inline]
pub fn roundeven_impl<F: Float>(x: F) -> F {
super::generic::rint_round(x, Round::Nearest).val
}