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

Commit 655e812

Browse files
committed
Rename Name to Identifier to avoid some ambiguity of "name"
1 parent 1e18307 commit 655e812

File tree

8 files changed

+35
-38
lines changed

8 files changed

+35
-38
lines changed

crates/libm-test/benches/random.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ where
4747
Op: MathOp,
4848
CachedInput: GenerateInput<Op::RustArgs>,
4949
{
50-
let name = Op::NAME_STR;
50+
let name = Op::NAME;
5151

5252
let ulp = libm_test::musl_allowed_ulp(name);
53-
let ctx = CheckCtx::new(ulp, Op::NAME, CheckBasis::Musl);
53+
let ctx = CheckCtx::new(ulp, Op::IDENTIFIER, CheckBasis::Musl);
5454
let benchvec: Vec<_> =
5555
random::get_test_cases::<Op::RustArgs>(&ctx).take(BENCH_ITER_ITEMS).collect();
5656

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +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.fn_name_str == "jn" || ctx.fn_name_str == "jnf" {
114-
&TEST_CASES_JN
115-
} else {
116-
&TEST_CASES
117-
};
113+
let inputs =
114+
if ctx.fn_name == "jn" || ctx.fn_name == "jnf" { &TEST_CASES_JN } else { &TEST_CASES };
118115
inputs.get_cases()
119116
}

crates/libm-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod precision;
66
mod test_traits;
77

88
pub use libm::support::{Float, Int};
9-
pub use op::{BaseName, MathOp, Name};
9+
pub use op::{BaseName, Identifier, MathOp};
1010
pub use precision::{MaybeOverride, SpecialCase, multiprec_allowed_ulp, musl_allowed_ulp};
1111
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, Hex, TupleCall};
1212

crates/libm-test/src/op.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
1616
use crate::{CheckOutput, Float, TupleCall};
1717

18-
/// An enum representing each possible routine name.
18+
/// An enum representing each possible symbol name (`sin`, `sinf`, `sinl`, etc).
1919
#[libm_macros::function_enum(BaseName)]
2020
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
21-
pub enum Name {}
21+
pub enum Identifier {}
2222

2323
/// The name without any type specifier, e.g. `sin` and `sinf` both become `sin`.
2424
#[libm_macros::base_name_enum]
@@ -58,13 +58,13 @@ pub trait MathOp {
5858
type RustRet: CheckOutput<Self::RustArgs>;
5959

6060
/// The name of this function, including suffix (e.g. `sin`, `sinf`).
61-
const NAME: Name;
61+
const IDENTIFIER: Identifier;
6262

6363
/// The name as a string.
64-
const NAME_STR: &'static str = Self::NAME.as_str();
64+
const NAME: &'static str = Self::IDENTIFIER.as_str();
6565

6666
/// The name of the function excluding the type suffix, e.g. `sin` and `sinf` are both `sin`.
67-
const BASE_NAME: BaseName = Self::NAME.base_name();
67+
const BASE_NAME: BaseName = Self::IDENTIFIER.base_name();
6868

6969
/// The function in `libm` which can be called.
7070
const ROUTINE: Self::RustFn;
@@ -96,7 +96,7 @@ macro_rules! do_thing {
9696
type RustArgs = $RustArgs;
9797
type RustRet = $RustRet;
9898

99-
const NAME: Name = Name::[< $fn_name:camel >];
99+
const IDENTIFIER: Identifier = Identifier::[< $fn_name:camel >];
100100
const ROUTINE: Self::RustFn = libm::$fn_name;
101101
}
102102
}

crates/libm-test/src/precision.rs

Lines changed: 12 additions & 12 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.fn_name_str == "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.fn_name_str == "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.fn_name_str == "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.fn_name_str == "lgammaf" || ctx.fn_name_str == "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.fn_name_str == "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.fn_name_str == "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.fn_name_str == "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.fn_name_str == "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.fn_name_str == "lgamma" || ctx.fn_name_str == "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.fn_name_str == "lgamma_r"
209+
&& ctx.fn_name == "lgamma_r"
210210
&& input.0 == f64::NEG_INFINITY
211211
&& actual.abs() == expected.abs()
212212
{
@@ -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.fn_name_str == "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.fn_name_str == "jn"
336+
if ctx.fn_name == "jn"
337337
&& input.1 == f64::NEG_INFINITY
338338
&& actual == F::ZERO
339339
&& expected == F::ZERO

crates/libm-test/src/test_traits.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ use std::fmt;
1111

1212
use anyhow::{Context, bail, ensure};
1313

14-
use crate::{BaseName, Float, Int, MaybeOverride, Name, SpecialCase, TestResult};
14+
use crate::{BaseName, Float, Identifier, Int, MaybeOverride, SpecialCase, TestResult};
1515

1616
/// Context passed to [`CheckOutput`].
1717
#[derive(Clone, Debug, PartialEq, Eq)]
1818
pub struct CheckCtx {
1919
/// Allowed ULP deviation
2020
pub ulp: u32,
21-
pub fn_name: Name,
21+
pub fn_ident: Identifier,
2222
pub base_name: BaseName,
2323
/// Function name.
24-
pub fn_name_str: &'static str,
24+
pub fn_name: &'static str,
2525
/// Return the unsuffixed version of the function name.
2626
pub base_name_str: &'static str,
2727
/// Source of truth for tests.
2828
pub basis: CheckBasis,
2929
}
3030

3131
impl CheckCtx {
32-
pub fn new(ulp: u32, fn_name: Name, basis: CheckBasis) -> Self {
32+
pub fn new(ulp: u32, fn_ident: Identifier, basis: CheckBasis) -> Self {
3333
Self {
3434
ulp,
35-
fn_name,
36-
fn_name_str: fn_name.as_str(),
37-
base_name: fn_name.base_name(),
38-
base_name_str: fn_name.base_name().as_str(),
35+
fn_ident,
36+
fn_name: fn_ident.as_str(),
37+
base_name: fn_ident.base_name(),
38+
base_name_str: fn_ident.base_name().as_str(),
3939
basis,
4040
}
4141
}

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ where
3434
Op: MathOp,
3535
CachedInput: GenerateInput<Op::RustArgs>,
3636
{
37-
let name = Op::NAME_STR;
37+
let name = Op::NAME;
3838
let ulp = musl_allowed_ulp(name);
39-
let ctx = CheckCtx::new(ulp, Op::NAME, CheckBasis::Musl);
39+
let ctx = CheckCtx::new(ulp, Op::IDENTIFIER, CheckBasis::Musl);
4040
let cases = random::get_test_cases::<Op::RustArgs>(&ctx);
4141

4242
for input in cases {

crates/libm-test/tests/multiprecision.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ where
2929
Op: MathOp + MpOp,
3030
CachedInput: GenerateInput<Op::RustArgs>,
3131
{
32-
let name = Op::NAME_STR;
32+
let name = Op::NAME;
3333

3434
let ulp = multiprec_allowed_ulp(name);
3535
let mut mp_vals = Op::new_mp();
36-
let ctx = CheckCtx::new(ulp, Op::NAME, CheckBasis::Mpfr);
36+
let ctx = CheckCtx::new(ulp, Op::IDENTIFIER, CheckBasis::Mpfr);
3737
let cases = random::get_test_cases::<Op::RustArgs>(&ctx);
3838

3939
for input in cases {

0 commit comments

Comments
 (0)