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

Commit 09dd0c8

Browse files
committed
Rename canonical_name to base_name
"Canonical" isn't really the right word here, update to "base".
1 parent 4845a7e commit 09dd0c8

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

crates/libm-test/src/gen/random.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub fn get_test_cases<RustArgs>(ctx: &CheckCtx) -> impl Iterator<Item = RustArgs
110110
where
111111
CachedInput: GenerateInput<RustArgs>,
112112
{
113-
let inputs = if ctx.fname == "jn" || ctx.fname == "jnf" { &TEST_CASES_JN } else { &TEST_CASES };
113+
let inputs =
114+
if ctx.fn_name == "jn" || ctx.fn_name == "jnf" { &TEST_CASES_JN } else { &TEST_CASES };
114115
inputs.get_cases()
115116
}

crates/libm-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include!(concat!(env!("OUT_DIR"), "/all_files.rs"));
1818

1919
/// Return the unsuffixed version of a function name; e.g. `abs` and `absf` both return `abs`,
2020
/// `lgamma_r` and `lgammaf_r` both return `lgamma_r`.
21-
pub fn canonical_name(name: &str) -> &str {
21+
pub fn base_name(name: &str) -> &str {
2222
let known_mappings = &[
2323
("erff", "erf"),
2424
("erf", "erf"),

crates/libm-test/src/precision.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,25 @@ impl MaybeOverride<(f32,)> for SpecialCase {
111111
ctx: &CheckCtx,
112112
) -> Option<TestResult> {
113113
if ctx.basis == CheckBasis::Musl {
114-
if ctx.fname == "expm1f" && input.0 > 80.0 && actual.is_infinite() {
114+
if ctx.fn_name == "expm1f" && input.0 > 80.0 && actual.is_infinite() {
115115
// we return infinity but the number is representable
116116
return XFAIL;
117117
}
118118

119-
if ctx.fname == "sinhf" && input.0.abs() > 80.0 && actual.is_nan() {
119+
if ctx.fn_name == "sinhf" && input.0.abs() > 80.0 && actual.is_nan() {
120120
// we return some NaN that should be real values or infinite
121121
// doesn't seem to happen on x86
122122
return XFAIL;
123123
}
124124
}
125125

126-
if ctx.fname == "acoshf" && input.0 < -1.0 {
126+
if ctx.fn_name == "acoshf" && input.0 < -1.0 {
127127
// acoshf is undefined for x <= 1.0, but we return a random result at lower
128128
// values.
129129
return XFAIL;
130130
}
131131

132-
if ctx.fname == "lgammaf" || ctx.fname == "lgammaf_r" && input.0 < 0.0 {
132+
if ctx.fn_name == "lgammaf" || ctx.fn_name == "lgammaf_r" && input.0 < 0.0 {
133133
// loggamma should not be defined for x < 0, yet we both return results
134134
return XFAIL;
135135
}
@@ -146,7 +146,7 @@ impl MaybeOverride<(f32,)> for SpecialCase {
146146
// On MPFR for lgammaf_r, we set -1 as the integer result for negative infinity but MPFR
147147
// sets +1
148148
if ctx.basis == CheckBasis::Mpfr
149-
&& ctx.fname == "lgammaf_r"
149+
&& ctx.fn_name == "lgammaf_r"
150150
&& input.0 == f32::NEG_INFINITY
151151
&& actual.abs() == expected.abs()
152152
{
@@ -166,13 +166,13 @@ impl MaybeOverride<(f64,)> for SpecialCase {
166166
ctx: &CheckCtx,
167167
) -> Option<TestResult> {
168168
if ctx.basis == CheckBasis::Musl {
169-
if cfg!(target_arch = "x86") && ctx.fname == "acosh" && input.0 < 1.0 {
169+
if cfg!(target_arch = "x86") && ctx.fn_name == "acosh" && input.0 < 1.0 {
170170
// The function is undefined, both implementations return random results
171171
return SKIP;
172172
}
173173

174174
if cfg!(x86_no_sse)
175-
&& ctx.fname == "ceil"
175+
&& ctx.fn_name == "ceil"
176176
&& input.0 < 0.0
177177
&& input.0 > -1.0
178178
&& expected == F::ZERO
@@ -183,13 +183,13 @@ impl MaybeOverride<(f64,)> for SpecialCase {
183183
}
184184
}
185185

186-
if ctx.fname == "acosh" && input.0 < 1.0 {
186+
if ctx.fn_name == "acosh" && input.0 < 1.0 {
187187
// The function is undefined for the inputs, musl and our libm both return
188188
// random results.
189189
return XFAIL;
190190
}
191191

192-
if ctx.fname == "lgamma" || ctx.fname == "lgamma_r" && input.0 < 0.0 {
192+
if ctx.fn_name == "lgamma" || ctx.fn_name == "lgamma_r" && input.0 < 0.0 {
193193
// loggamma should not be defined for x < 0, yet we both return results
194194
return XFAIL;
195195
}
@@ -206,7 +206,7 @@ impl MaybeOverride<(f64,)> for SpecialCase {
206206
// On MPFR for lgamma_r, we set -1 as the integer result for negative infinity but MPFR
207207
// sets +1
208208
if ctx.basis == CheckBasis::Mpfr
209-
&& ctx.fname == "lgamma_r"
209+
&& ctx.fn_name == "lgamma_r"
210210
&& input.0 == f64::NEG_INFINITY
211211
&& actual.abs() == expected.abs()
212212
{
@@ -219,7 +219,7 @@ impl MaybeOverride<(f64,)> for SpecialCase {
219219

220220
/// Check NaN bits if the function requires it
221221
fn maybe_check_nan_bits<F: Float>(actual: F, expected: F, ctx: &CheckCtx) -> Option<TestResult> {
222-
if !(ctx.canonical_name == "fabs" || ctx.canonical_name == "copysign") {
222+
if !(ctx.base_name == "fabs" || ctx.base_name == "copysign") {
223223
return None;
224224
}
225225

@@ -277,7 +277,7 @@ fn maybe_skip_binop_nan<F1: Float, F2: Float>(
277277
) -> Option<TestResult> {
278278
match ctx.basis {
279279
CheckBasis::Musl => {
280-
if (ctx.canonical_name == "fmax" || ctx.canonical_name == "fmin")
280+
if (ctx.base_name == "fmax" || ctx.base_name == "fmin")
281281
&& (input.0.is_nan() || input.1.is_nan())
282282
&& expected.is_nan()
283283
{
@@ -287,7 +287,7 @@ fn maybe_skip_binop_nan<F1: Float, F2: Float>(
287287
}
288288
}
289289
CheckBasis::Mpfr => {
290-
if ctx.canonical_name == "copysign" && input.1.is_nan() {
290+
if ctx.base_name == "copysign" && input.1.is_nan() {
291291
SKIP
292292
} else {
293293
None
@@ -308,7 +308,7 @@ impl MaybeOverride<(i32, f32)> for SpecialCase {
308308
CheckBasis::Musl => bessel_prec_dropoff(input, ulp, ctx),
309309
CheckBasis::Mpfr => {
310310
// We return +0.0, MPFR returns -0.0
311-
if ctx.fname == "jnf"
311+
if ctx.fn_name == "jnf"
312312
&& input.1 == f32::NEG_INFINITY
313313
&& actual == F::ZERO
314314
&& expected == F::ZERO
@@ -333,7 +333,7 @@ impl MaybeOverride<(i32, f64)> for SpecialCase {
333333
CheckBasis::Musl => bessel_prec_dropoff(input, ulp, ctx),
334334
CheckBasis::Mpfr => {
335335
// We return +0.0, MPFR returns -0.0
336-
if ctx.fname == "jn"
336+
if ctx.fn_name == "jn"
337337
&& input.1 == f64::NEG_INFINITY
338338
&& actual == F::ZERO
339339
&& expected == F::ZERO
@@ -353,7 +353,7 @@ fn bessel_prec_dropoff<F: Float>(
353353
ulp: &mut u32,
354354
ctx: &CheckCtx,
355355
) -> Option<TestResult> {
356-
if ctx.canonical_name == "jn" {
356+
if ctx.base_name == "jn" {
357357
if input.0 > 4000 {
358358
return XFAIL;
359359
} else if input.0 > 2000 {

crates/libm-test/src/test_traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ pub struct CheckCtx {
3333
/// Allowed ULP deviation
3434
pub ulp: u32,
3535
/// Function name.
36-
pub fname: &'static str,
36+
pub fn_name: &'static str,
3737
/// Return the unsuffixed version of the function name.
38-
pub canonical_name: &'static str,
38+
pub base_name: &'static str,
3939
/// Source of truth for tests.
4040
pub basis: CheckBasis,
4141
}
4242

4343
impl CheckCtx {
4444
pub fn new(ulp: u32, fname: &'static str, basis: CheckBasis) -> Self {
45-
let canonical_fname = crate::canonical_name(fname);
46-
Self { ulp, fname, canonical_name: canonical_fname, basis }
45+
let base_name = crate::base_name(fname);
46+
Self { ulp, fn_name: fname, base_name, basis }
4747
}
4848
}
4949

src/math/support/macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ macro_rules! cfg_if {
5757
/// (`unstable-intrinsics`, `arch`, `force-soft-floats`), this macro handles that part.
5858
macro_rules! select_implementation {
5959
(
60-
name: $fname:ident,
60+
name: $fn_name:ident,
6161
// Configuration meta for when to use arch-specific implementation that requires hard
6262
// float ops
6363
$( use_arch: $use_arch:meta, )?
@@ -76,7 +76,7 @@ macro_rules! select_implementation {
7676
select_implementation! {
7777
@cfg $($use_arch_required)?;
7878
if true {
79-
return super::arch::$fname( $($arg),+ );
79+
return super::arch::$fn_name( $($arg),+ );
8080
}
8181
}
8282

@@ -86,7 +86,7 @@ macro_rules! select_implementation {
8686
@cfg $($use_arch)?;
8787
// Wrap in `if true` to avoid unused warnings
8888
if true {
89-
return super::arch::$fname( $($arg),+ );
89+
return super::arch::$fn_name( $($arg),+ );
9090
}
9191
}
9292

@@ -96,7 +96,7 @@ macro_rules! select_implementation {
9696
select_implementation! {
9797
@cfg $( $use_intrinsic )?;
9898
if true {
99-
return super::arch::intrinsics::$fname( $($arg),+ );
99+
return super::arch::intrinsics::$fn_name( $($arg),+ );
100100
}
101101
}
102102
};

0 commit comments

Comments
 (0)