Add fmodf16 using the generic implementation

This commit is contained in:
Trevor Gross 2025-01-24 05:09:08 +00:00
parent 08eda86de2
commit 67218cbaa5
10 changed files with 37 additions and 1 deletions

View file

@ -47,7 +47,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
FloatTy::F16,
Signature { args: &[Ty::F16, Ty::F16], returns: &[Ty::F16] },
None,
&["copysignf16", "fdimf16", "fmaxf16", "fminf16"],
&["copysignf16", "fdimf16", "fmaxf16", "fminf16", "fmodf16"],
),
(
// `(f32, f32) -> f32`

View file

@ -111,6 +111,7 @@ main!(
icount_bench_fmin_group,
icount_bench_fminf_group,
icount_bench_fmod_group,
icount_bench_fmodf16_group,
icount_bench_fmodf_group,
icount_bench_frexp_group,
icount_bench_frexpf_group,

View file

@ -131,6 +131,7 @@ libm_macros::for_each_function! {
| fmaxf16
| fminf128
| fminf16
| fmodf16
| rintf128
| rintf16
| roundf128

View file

@ -152,6 +152,7 @@ libm_macros::for_each_function! {
floorf16,
fmod,
fmodf,
fmodf16,
frexp,
frexpf,
ilogb,
@ -525,6 +526,22 @@ impl MpOp for crate::op::lgammaf_r::Routine {
}
}
// No fmodf128 yet
impl MpOp for crate::op::fmodf16::Routine {
type MpTy = (MpFloat, MpFloat);
fn new_mp() -> Self::MpTy {
(new_mpfloat::<Self::FTy>(), new_mpfloat::<Self::FTy>())
}
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
this.0.assign(input.0);
this.1.assign(input.1);
let ord = this.0.rem_assign_round(&this.1, Nearest);
prep_retval::<Self::RustRet>(&mut this.0, ord)
}
}
/* stub implementations so we don't need to special case them */
impl MpOp for crate::op::nextafter::Routine {

View file

@ -93,6 +93,7 @@ libm_macros::for_each_function! {
fmaxf16,
fminf128,
fminf16,
fmodf16,
rintf128,
rintf16,
roundf128,

View file

@ -100,6 +100,7 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
| fmaxf16
| fminf128
| fminf16
| fmodf16
| rintf128
| rintf16
| roundf128

View file

@ -449,6 +449,13 @@
],
"type": "f32"
},
"fmodf16": {
"sources": [
"src/math/fmodf16.rs",
"src/math/generic/fmod.rs"
],
"type": "f16"
},
"frexp": {
"sources": [
"src/libm_helper.rs",

View file

@ -63,6 +63,7 @@ fminf128
fminf16
fmod
fmodf
fmodf16
frexp
frexpf
hypot

View file

@ -0,0 +1,5 @@
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn fmodf16(x: f16, y: f16) -> f16 {
super::generic::fmod(x, y)
}

View file

@ -348,6 +348,7 @@ cfg_if! {
mod floorf16;
mod fmaxf16;
mod fminf16;
mod fmodf16;
mod rintf16;
mod roundf16;
mod sqrtf16;
@ -360,6 +361,7 @@ cfg_if! {
pub use self::floorf16::floorf16;
pub use self::fmaxf16::fmaxf16;
pub use self::fminf16::fminf16;
pub use self::fmodf16::fmodf16;
pub use self::rintf16::rintf16;
pub use self::roundf16::roundf16;
pub use self::sqrtf16::sqrtf16;