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

Commit 39ceb34

Browse files
committed
Add fmodf16 and fmodf128
1 parent d48187a commit 39ceb34

File tree

11 files changed

+57
-17
lines changed

11 files changed

+57
-17
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
4747
FloatTy::F16,
4848
Signature { args: &[Ty::F16, Ty::F16], returns: &[Ty::F16] },
4949
None,
50-
&["copysignf16", "fdimf16", "fmaxf16", "fminf16"],
50+
&["copysignf16", "fdimf16", "fmaxf16", "fminf16", "fmodf16"],
5151
),
5252
(
5353
// `(f32, f32) -> f32`
@@ -90,7 +90,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
9090
FloatTy::F128,
9191
Signature { args: &[Ty::F128, Ty::F128], returns: &[Ty::F128] },
9292
None,
93-
&["copysignf128", "fdimf128", "fmaxf128", "fminf128"],
93+
&["copysignf128", "fdimf128", "fmaxf128", "fminf128", "fmodf128"],
9494
),
9595
(
9696
// `(f32, f32, f32) -> f32`

crates/libm-test/benches/icount.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ main!(
111111
icount_bench_fmin_group,
112112
icount_bench_fminf_group,
113113
icount_bench_fmod_group,
114+
icount_bench_fmodf128_group,
115+
icount_bench_fmodf16_group,
114116
icount_bench_fmodf_group,
115117
icount_bench_frexp_group,
116118
icount_bench_frexpf_group,

crates/libm-test/benches/random.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ libm_macros::for_each_function! {
131131
| fmaxf16
132132
| fminf128
133133
| fminf16
134+
| fmodf128
135+
| fmodf16
134136
| rintf128
135137
| rintf16
136138
| roundf128

crates/libm-test/src/mpfloat.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ libm_macros::for_each_function! {
152152
floorf16,
153153
fmod,
154154
fmodf,
155+
fmodf128,
156+
fmodf16,
155157
frexp,
156158
frexpf,
157159
ilogb,
@@ -300,21 +302,6 @@ macro_rules! impl_op_for_ty {
300302
}
301303
}
302304

303-
impl MpOp for crate::op::[<fmod $suffix>]::Routine {
304-
type MpTy = (MpFloat, MpFloat);
305-
306-
fn new_mp() -> Self::MpTy {
307-
(new_mpfloat::<Self::FTy>(), new_mpfloat::<Self::FTy>())
308-
}
309-
310-
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
311-
this.0.assign(input.0);
312-
this.1.assign(input.1);
313-
let ord = this.0.rem_assign_round(&this.1, Nearest);
314-
prep_retval::<Self::RustRet>(&mut this.0, ord)
315-
}
316-
}
317-
318305
impl MpOp for crate::op::[<frexp $suffix>]::Routine {
319306
type MpTy = MpFloat;
320307

@@ -480,6 +467,21 @@ macro_rules! impl_op_for_ty_all {
480467
prep_retval::<Self::RustRet>(&mut this.0, Ordering::Equal)
481468
}
482469
}
470+
471+
impl MpOp for crate::op::[<fmod $suffix>]::Routine {
472+
type MpTy = (MpFloat, MpFloat);
473+
474+
fn new_mp() -> Self::MpTy {
475+
(new_mpfloat::<Self::FTy>(), new_mpfloat::<Self::FTy>())
476+
}
477+
478+
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
479+
this.0.assign(input.0);
480+
this.1.assign(input.1);
481+
let ord = this.0.rem_assign_round(&this.1, Nearest);
482+
prep_retval::<Self::RustRet>(&mut this.0, ord)
483+
}
484+
}
483485
}
484486
};
485487
}

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ libm_macros::for_each_function! {
9393
fmaxf16,
9494
fminf128,
9595
fminf16,
96+
fmodf128,
97+
fmodf16,
9698
rintf128,
9799
rintf16,
98100
roundf128,

crates/util/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
100100
| fmaxf16
101101
| fminf128
102102
| fminf16
103+
| fmodf128
104+
| fmodf16
103105
| rintf128
104106
| rintf16
105107
| roundf128

etc/function-definitions.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,20 @@
449449
],
450450
"type": "f32"
451451
},
452+
"fmodf128": {
453+
"sources": [
454+
"src/math/fmodf128.rs",
455+
"src/math/generic/fmod.rs"
456+
],
457+
"type": "f128"
458+
},
459+
"fmodf16": {
460+
"sources": [
461+
"src/math/fmodf16.rs",
462+
"src/math/generic/fmod.rs"
463+
],
464+
"type": "f16"
465+
},
452466
"frexp": {
453467
"sources": [
454468
"src/libm_helper.rs",

etc/function-list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ fminf128
6363
fminf16
6464
fmod
6565
fmodf
66+
fmodf128
67+
fmodf16
6668
frexp
6769
frexpf
6870
hypot

src/math/fmodf128.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmodf128(x: f128, y: f128) -> f128 {
4+
super::generic::fmod(x, y)
5+
}

src/math/fmodf16.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmodf16(x: f16, y: f16) -> f16 {
4+
super::generic::fmod(x, y)
5+
}

src/math/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ cfg_if! {
348348
mod floorf16;
349349
mod fmaxf16;
350350
mod fminf16;
351+
mod fmodf16;
351352
mod rintf16;
352353
mod roundf16;
353354
mod sqrtf16;
@@ -360,6 +361,7 @@ cfg_if! {
360361
pub use self::floorf16::floorf16;
361362
pub use self::fmaxf16::fmaxf16;
362363
pub use self::fminf16::fminf16;
364+
pub use self::fmodf16::fmodf16;
363365
pub use self::rintf16::rintf16;
364366
pub use self::roundf16::roundf16;
365367
pub use self::sqrtf16::sqrtf16;
@@ -376,6 +378,7 @@ cfg_if! {
376378
mod floorf128;
377379
mod fmaxf128;
378380
mod fminf128;
381+
mod fmodf128;
379382
mod rintf128;
380383
mod roundf128;
381384
mod sqrtf128;
@@ -388,6 +391,7 @@ cfg_if! {
388391
pub use self::floorf128::floorf128;
389392
pub use self::fmaxf128::fmaxf128;
390393
pub use self::fminf128::fminf128;
394+
pub use self::fmodf128::fmodf128;
391395
pub use self::rintf128::rintf128;
392396
pub use self::roundf128::roundf128;
393397
pub use self::sqrtf128::sqrtf128;

0 commit comments

Comments
 (0)