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

Commit c997735

Browse files
committed
Add scalbnf16, scalbnf128, ldexpf16, and ldexpf128
Use the generic `scalbn` to provide `f16` and `f128` versions, which also work for `ldexp`.
1 parent 220c8e5 commit c997735

File tree

13 files changed

+116
-28
lines changed

13 files changed

+116
-28
lines changed

crates/libm-macros/src/shared.rs

+14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
134134
None,
135135
&["jn", "yn"],
136136
),
137+
(
138+
// `(f16, i32) -> f16`
139+
FloatTy::F16,
140+
Signature { args: &[Ty::F16, Ty::I32], returns: &[Ty::F16] },
141+
None,
142+
&["scalbnf16", "ldexpf16"],
143+
),
137144
(
138145
// `(f32, i32) -> f32`
139146
FloatTy::F32,
@@ -148,6 +155,13 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
148155
None,
149156
&["scalbn", "ldexp"],
150157
),
158+
(
159+
// `(f128, i32) -> f128`
160+
FloatTy::F128,
161+
Signature { args: &[Ty::F128, Ty::I32], returns: &[Ty::F128] },
162+
None,
163+
&["scalbnf128", "ldexpf128"],
164+
),
151165
(
152166
// `(f32, &mut f32) -> f32` as `(f32) -> (f32, f32)`
153167
FloatTy::F32,

crates/libm-test/benches/random.rs

+4
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ libm_macros::for_each_function! {
127127
| fdimf16
128128
| floorf128
129129
| floorf16
130+
| ldexpf128
131+
| ldexpf16
130132
| rintf128
131133
| rintf16
134+
| scalbnf128
135+
| scalbnf16
132136
| sqrtf128
133137
| sqrtf16
134138
| truncf128

crates/libm-test/src/mpfloat.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ libm_macros::for_each_function! {
160160
jnf,
161161
ldexp,
162162
ldexpf,
163+
ldexpf128,
164+
ldexpf16,
163165
lgamma_r,
164166
lgammaf_r,
165167
modf,
@@ -177,6 +179,8 @@ libm_macros::for_each_function! {
177179
roundf,
178180
scalbn,
179181
scalbnf,
182+
scalbnf128,
183+
scalbnf16,
180184
sincos,sincosf,
181185
trunc,
182186
truncf,
@@ -368,34 +372,6 @@ macro_rules! impl_op_for_ty {
368372
}
369373
}
370374

371-
// `ldexp` and `scalbn` are the same for binary floating point, so just forward all
372-
// methods.
373-
impl MpOp for crate::op::[<ldexp $suffix>]::Routine {
374-
type MpTy = <crate::op::[<scalbn $suffix>]::Routine as MpOp>::MpTy;
375-
376-
fn new_mp() -> Self::MpTy {
377-
<crate::op::[<scalbn $suffix>]::Routine as MpOp>::new_mp()
378-
}
379-
380-
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
381-
<crate::op::[<scalbn $suffix>]::Routine as MpOp>::run(this, input)
382-
}
383-
}
384-
385-
impl MpOp for crate::op::[<scalbn $suffix>]::Routine {
386-
type MpTy = MpFloat;
387-
388-
fn new_mp() -> Self::MpTy {
389-
new_mpfloat::<Self::FTy>()
390-
}
391-
392-
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
393-
this.assign(input.0);
394-
*this <<= input.1;
395-
prep_retval::<Self::FTy>(this, Ordering::Equal)
396-
}
397-
}
398-
399375
impl MpOp for crate::op::[<sincos $suffix>]::Routine {
400376
type MpTy = (MpFloat, MpFloat);
401377

@@ -476,6 +452,34 @@ macro_rules! impl_op_for_ty_all {
476452
prep_retval::<Self::RustRet>(&mut this.0, Ordering::Equal)
477453
}
478454
}
455+
456+
// `ldexp` and `scalbn` are the same for binary floating point, so just forward all
457+
// methods.
458+
impl MpOp for crate::op::[<ldexp $suffix>]::Routine {
459+
type MpTy = <crate::op::[<scalbn $suffix>]::Routine as MpOp>::MpTy;
460+
461+
fn new_mp() -> Self::MpTy {
462+
<crate::op::[<scalbn $suffix>]::Routine as MpOp>::new_mp()
463+
}
464+
465+
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
466+
<crate::op::[<scalbn $suffix>]::Routine as MpOp>::run(this, input)
467+
}
468+
}
469+
470+
impl MpOp for crate::op::[<scalbn $suffix>]::Routine {
471+
type MpTy = MpFloat;
472+
473+
fn new_mp() -> Self::MpTy {
474+
new_mpfloat::<Self::FTy>()
475+
}
476+
477+
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
478+
this.assign(input.0);
479+
*this <<= input.1;
480+
prep_retval::<Self::FTy>(this, Ordering::Equal)
481+
}
482+
}
479483
}
480484
};
481485
}

crates/libm-test/src/precision.rs

+4
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,12 @@ fn int_float_common<F1: Float, F2: Float>(
585585
DEFAULT
586586
}
587587

588+
#[cfg(f16_enabled)]
589+
impl MaybeOverride<(f16, i32)> for SpecialCase {}
588590
impl MaybeOverride<(f32, i32)> for SpecialCase {}
589591
impl MaybeOverride<(f64, i32)> for SpecialCase {}
592+
#[cfg(f128_enabled)]
593+
impl MaybeOverride<(f128, i32)> for SpecialCase {}
590594

591595
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {
592596
fn check_float<F: Float>(

crates/libm-test/tests/compare_built_musl.rs

+4
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ libm_macros::for_each_function! {
8989
fdimf16,
9090
floorf128,
9191
floorf16,
92+
ldexpf128,
93+
ldexpf16,
9294
rintf128,
9395
rintf16,
96+
scalbnf128,
97+
scalbnf16,
9498
sqrtf128,
9599
sqrtf16,
96100
truncf128,

crates/util/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9696
| fdimf16
9797
| floorf128
9898
| floorf16
99+
| ldexpf128
100+
| ldexpf16
99101
| rintf128
100102
| rintf16
103+
| scalbnf128
104+
| scalbnf16
101105
| sqrtf128
102106
| sqrtf16
103107
| truncf128

etc/function-definitions.json

+26
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,18 @@
506506
],
507507
"type": "f32"
508508
},
509+
"ldexpf128": {
510+
"sources": [
511+
"src/math/ldexpf128.rs"
512+
],
513+
"type": "f128"
514+
},
515+
"ldexpf16": {
516+
"sources": [
517+
"src/math/ldexpf16.rs"
518+
],
519+
"type": "f16"
520+
},
509521
"lgamma": {
510522
"sources": [
511523
"src/libm_helper.rs",
@@ -710,6 +722,20 @@
710722
],
711723
"type": "f32"
712724
},
725+
"scalbnf128": {
726+
"sources": [
727+
"src/math/generic/scalbn.rs",
728+
"src/math/scalbnf128.rs"
729+
],
730+
"type": "f128"
731+
},
732+
"scalbnf16": {
733+
"sources": [
734+
"src/math/generic/scalbn.rs",
735+
"src/math/scalbnf16.rs"
736+
],
737+
"type": "f16"
738+
},
713739
"sin": {
714740
"sources": [
715741
"src/libm_helper.rs",

etc/function-list.txt

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jn
7373
jnf
7474
ldexp
7575
ldexpf
76+
ldexpf128
77+
ldexpf16
7678
lgamma
7779
lgamma_r
7880
lgammaf
@@ -103,6 +105,8 @@ round
103105
roundf
104106
scalbn
105107
scalbnf
108+
scalbnf128
109+
scalbnf16
106110
sin
107111
sincos
108112
sincosf

src/math/ldexpf128.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn ldexpf128(x: f128, n: i32) -> f128 {
3+
super::scalbnf128(x, n)
4+
}

src/math/ldexpf16.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn ldexpf16(x: f16, n: i32) -> f16 {
3+
super::scalbnf16(x, n)
4+
}

src/math/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ cfg_if! {
346346
mod fabsf16;
347347
mod fdimf16;
348348
mod floorf16;
349+
mod ldexpf16;
349350
mod rintf16;
351+
mod scalbnf16;
350352
mod sqrtf16;
351353
mod truncf16;
352354

@@ -355,7 +357,9 @@ cfg_if! {
355357
pub use self::fabsf16::fabsf16;
356358
pub use self::fdimf16::fdimf16;
357359
pub use self::floorf16::floorf16;
360+
pub use self::ldexpf16::ldexpf16;
358361
pub use self::rintf16::rintf16;
362+
pub use self::scalbnf16::scalbnf16;
359363
pub use self::sqrtf16::sqrtf16;
360364
pub use self::truncf16::truncf16;
361365
}
@@ -368,7 +372,9 @@ cfg_if! {
368372
mod fabsf128;
369373
mod fdimf128;
370374
mod floorf128;
375+
mod ldexpf128;
371376
mod rintf128;
377+
mod scalbnf128;
372378
mod sqrtf128;
373379
mod truncf128;
374380

@@ -377,7 +383,9 @@ cfg_if! {
377383
pub use self::fabsf128::fabsf128;
378384
pub use self::fdimf128::fdimf128;
379385
pub use self::floorf128::floorf128;
386+
pub use self::ldexpf128::ldexpf128;
380387
pub use self::rintf128::rintf128;
388+
pub use self::scalbnf128::scalbnf128;
381389
pub use self::sqrtf128::sqrtf128;
382390
pub use self::truncf128::truncf128;
383391
}

src/math/scalbnf128.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn scalbnf128(x: f128, n: i32) -> f128 {
3+
super::generic::scalbn(x, n)
4+
}

src/math/scalbnf16.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn scalbnf16(x: f16, n: i32) -> f16 {
3+
super::generic::scalbn(x, n)
4+
}

0 commit comments

Comments
 (0)