Rename Name to Identifier to avoid some ambiguity of "name"
This commit is contained in:
@@ -110,10 +110,7 @@ pub fn get_test_cases<RustArgs>(ctx: &CheckCtx) -> impl Iterator<Item = RustArgs
|
||||
where
|
||||
CachedInput: GenerateInput<RustArgs>,
|
||||
{
|
||||
let inputs = if ctx.fn_name_str == "jn" || ctx.fn_name_str == "jnf" {
|
||||
&TEST_CASES_JN
|
||||
} else {
|
||||
&TEST_CASES
|
||||
};
|
||||
let inputs =
|
||||
if ctx.fn_name == "jn" || ctx.fn_name == "jnf" { &TEST_CASES_JN } else { &TEST_CASES };
|
||||
inputs.get_cases()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ mod precision;
|
||||
mod test_traits;
|
||||
|
||||
pub use libm::support::{Float, Int};
|
||||
pub use op::{BaseName, MathOp, Name};
|
||||
pub use op::{BaseName, Identifier, MathOp};
|
||||
pub use precision::{MaybeOverride, SpecialCase, multiprec_allowed_ulp, musl_allowed_ulp};
|
||||
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, Hex, TupleCall};
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
|
||||
use crate::{CheckOutput, Float, TupleCall};
|
||||
|
||||
/// An enum representing each possible routine name.
|
||||
/// An enum representing each possible symbol name (`sin`, `sinf`, `sinl`, etc).
|
||||
#[libm_macros::function_enum(BaseName)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Name {}
|
||||
pub enum Identifier {}
|
||||
|
||||
/// The name without any type specifier, e.g. `sin` and `sinf` both become `sin`.
|
||||
#[libm_macros::base_name_enum]
|
||||
@@ -58,13 +58,13 @@ pub trait MathOp {
|
||||
type RustRet: CheckOutput<Self::RustArgs>;
|
||||
|
||||
/// The name of this function, including suffix (e.g. `sin`, `sinf`).
|
||||
const NAME: Name;
|
||||
const IDENTIFIER: Identifier;
|
||||
|
||||
/// The name as a string.
|
||||
const NAME_STR: &'static str = Self::NAME.as_str();
|
||||
const NAME: &'static str = Self::IDENTIFIER.as_str();
|
||||
|
||||
/// The name of the function excluding the type suffix, e.g. `sin` and `sinf` are both `sin`.
|
||||
const BASE_NAME: BaseName = Self::NAME.base_name();
|
||||
const BASE_NAME: BaseName = Self::IDENTIFIER.base_name();
|
||||
|
||||
/// The function in `libm` which can be called.
|
||||
const ROUTINE: Self::RustFn;
|
||||
@@ -96,7 +96,7 @@ macro_rules! do_thing {
|
||||
type RustArgs = $RustArgs;
|
||||
type RustRet = $RustRet;
|
||||
|
||||
const NAME: Name = Name::[< $fn_name:camel >];
|
||||
const IDENTIFIER: Identifier = Identifier::[< $fn_name:camel >];
|
||||
const ROUTINE: Self::RustFn = libm::$fn_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,25 +111,25 @@ impl MaybeOverride<(f32,)> for SpecialCase {
|
||||
ctx: &CheckCtx,
|
||||
) -> Option<TestResult> {
|
||||
if ctx.basis == CheckBasis::Musl {
|
||||
if ctx.fn_name_str == "expm1f" && input.0 > 80.0 && actual.is_infinite() {
|
||||
if ctx.fn_name == "expm1f" && input.0 > 80.0 && actual.is_infinite() {
|
||||
// we return infinity but the number is representable
|
||||
return XFAIL;
|
||||
}
|
||||
|
||||
if ctx.fn_name_str == "sinhf" && input.0.abs() > 80.0 && actual.is_nan() {
|
||||
if ctx.fn_name == "sinhf" && input.0.abs() > 80.0 && actual.is_nan() {
|
||||
// we return some NaN that should be real values or infinite
|
||||
// doesn't seem to happen on x86
|
||||
return XFAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.fn_name_str == "acoshf" && input.0 < -1.0 {
|
||||
if ctx.fn_name == "acoshf" && input.0 < -1.0 {
|
||||
// acoshf is undefined for x <= 1.0, but we return a random result at lower
|
||||
// values.
|
||||
return XFAIL;
|
||||
}
|
||||
|
||||
if ctx.fn_name_str == "lgammaf" || ctx.fn_name_str == "lgammaf_r" && input.0 < 0.0 {
|
||||
if ctx.fn_name == "lgammaf" || ctx.fn_name == "lgammaf_r" && input.0 < 0.0 {
|
||||
// loggamma should not be defined for x < 0, yet we both return results
|
||||
return XFAIL;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ impl MaybeOverride<(f32,)> for SpecialCase {
|
||||
// On MPFR for lgammaf_r, we set -1 as the integer result for negative infinity but MPFR
|
||||
// sets +1
|
||||
if ctx.basis == CheckBasis::Mpfr
|
||||
&& ctx.fn_name_str == "lgammaf_r"
|
||||
&& ctx.fn_name == "lgammaf_r"
|
||||
&& input.0 == f32::NEG_INFINITY
|
||||
&& actual.abs() == expected.abs()
|
||||
{
|
||||
@@ -166,13 +166,13 @@ impl MaybeOverride<(f64,)> for SpecialCase {
|
||||
ctx: &CheckCtx,
|
||||
) -> Option<TestResult> {
|
||||
if ctx.basis == CheckBasis::Musl {
|
||||
if cfg!(target_arch = "x86") && ctx.fn_name_str == "acosh" && input.0 < 1.0 {
|
||||
if cfg!(target_arch = "x86") && ctx.fn_name == "acosh" && input.0 < 1.0 {
|
||||
// The function is undefined, both implementations return random results
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
if cfg!(x86_no_sse)
|
||||
&& ctx.fn_name_str == "ceil"
|
||||
&& ctx.fn_name == "ceil"
|
||||
&& input.0 < 0.0
|
||||
&& input.0 > -1.0
|
||||
&& expected == F::ZERO
|
||||
@@ -183,13 +183,13 @@ impl MaybeOverride<(f64,)> for SpecialCase {
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.fn_name_str == "acosh" && input.0 < 1.0 {
|
||||
if ctx.fn_name == "acosh" && input.0 < 1.0 {
|
||||
// The function is undefined for the inputs, musl and our libm both return
|
||||
// random results.
|
||||
return XFAIL;
|
||||
}
|
||||
|
||||
if ctx.fn_name_str == "lgamma" || ctx.fn_name_str == "lgamma_r" && input.0 < 0.0 {
|
||||
if ctx.fn_name == "lgamma" || ctx.fn_name == "lgamma_r" && input.0 < 0.0 {
|
||||
// loggamma should not be defined for x < 0, yet we both return results
|
||||
return XFAIL;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ impl MaybeOverride<(f64,)> for SpecialCase {
|
||||
// On MPFR for lgamma_r, we set -1 as the integer result for negative infinity but MPFR
|
||||
// sets +1
|
||||
if ctx.basis == CheckBasis::Mpfr
|
||||
&& ctx.fn_name_str == "lgamma_r"
|
||||
&& ctx.fn_name == "lgamma_r"
|
||||
&& input.0 == f64::NEG_INFINITY
|
||||
&& actual.abs() == expected.abs()
|
||||
{
|
||||
@@ -308,7 +308,7 @@ impl MaybeOverride<(i32, f32)> for SpecialCase {
|
||||
CheckBasis::Musl => bessel_prec_dropoff(input, ulp, ctx),
|
||||
CheckBasis::Mpfr => {
|
||||
// We return +0.0, MPFR returns -0.0
|
||||
if ctx.fn_name_str == "jnf"
|
||||
if ctx.fn_name == "jnf"
|
||||
&& input.1 == f32::NEG_INFINITY
|
||||
&& actual == F::ZERO
|
||||
&& expected == F::ZERO
|
||||
@@ -333,7 +333,7 @@ impl MaybeOverride<(i32, f64)> for SpecialCase {
|
||||
CheckBasis::Musl => bessel_prec_dropoff(input, ulp, ctx),
|
||||
CheckBasis::Mpfr => {
|
||||
// We return +0.0, MPFR returns -0.0
|
||||
if ctx.fn_name_str == "jn"
|
||||
if ctx.fn_name == "jn"
|
||||
&& input.1 == f64::NEG_INFINITY
|
||||
&& actual == F::ZERO
|
||||
&& expected == F::ZERO
|
||||
|
||||
@@ -11,17 +11,17 @@ use std::fmt;
|
||||
|
||||
use anyhow::{Context, bail, ensure};
|
||||
|
||||
use crate::{BaseName, Float, Int, MaybeOverride, Name, SpecialCase, TestResult};
|
||||
use crate::{BaseName, Float, Identifier, Int, MaybeOverride, SpecialCase, TestResult};
|
||||
|
||||
/// Context passed to [`CheckOutput`].
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CheckCtx {
|
||||
/// Allowed ULP deviation
|
||||
pub ulp: u32,
|
||||
pub fn_name: Name,
|
||||
pub fn_ident: Identifier,
|
||||
pub base_name: BaseName,
|
||||
/// Function name.
|
||||
pub fn_name_str: &'static str,
|
||||
pub fn_name: &'static str,
|
||||
/// Return the unsuffixed version of the function name.
|
||||
pub base_name_str: &'static str,
|
||||
/// Source of truth for tests.
|
||||
@@ -29,13 +29,13 @@ pub struct CheckCtx {
|
||||
}
|
||||
|
||||
impl CheckCtx {
|
||||
pub fn new(ulp: u32, fn_name: Name, basis: CheckBasis) -> Self {
|
||||
pub fn new(ulp: u32, fn_ident: Identifier, basis: CheckBasis) -> Self {
|
||||
Self {
|
||||
ulp,
|
||||
fn_name,
|
||||
fn_name_str: fn_name.as_str(),
|
||||
base_name: fn_name.base_name(),
|
||||
base_name_str: fn_name.base_name().as_str(),
|
||||
fn_ident,
|
||||
fn_name: fn_ident.as_str(),
|
||||
base_name: fn_ident.base_name(),
|
||||
base_name_str: fn_ident.base_name().as_str(),
|
||||
basis,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user