Skip to main content

decimal_scaled_golden/support/
function.rs

1// SPDX-FileCopyrightText: 2026 John Moxley
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4/// The functions the golden set covers. `arity` is how many inputs precede
5/// the output on a golden file line.
6#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
7pub enum Function {
8    // unary
9    Sqrt, Cbrt, Exp, Ln, Log2, Log10, Exp2,
10    Sin, Cos, Tan, Atan, Asin, Acos,
11    Sinh, Cosh, Tanh, Asinh, Acosh, Atanh,
12    // binary
13    Log, Atan2, Powf, Hypot, Add, Sub, Mul, Div, Rem,
14}
15
16impl Function {
17    pub fn arity(self) -> usize {
18        use Function::*;
19        match self {
20            Log | Atan2 | Powf | Hypot | Add | Sub | Mul | Div | Rem => 2,
21            _ => 1,
22        }
23    }
24    /// Canonical lowercase name, matching the golden file naming.
25    pub fn name(self) -> &'static str {
26        use Function::*;
27        match self {
28            Sqrt => "sqrt", Cbrt => "cbrt", Exp => "exp", Ln => "ln",
29            Log2 => "log2", Log10 => "log10", Exp2 => "exp2",
30            Sin => "sin", Cos => "cos", Tan => "tan",
31            Atan => "atan", Asin => "asin", Acos => "acos",
32            Sinh => "sinh", Cosh => "cosh", Tanh => "tanh",
33            Asinh => "asinh", Acosh => "acosh", Atanh => "atanh",
34            Log => "log", Atan2 => "atan2", Powf => "powf", Hypot => "hypot",
35            Add => "add", Sub => "sub", Mul => "mul", Div => "div", Rem => "rem",
36        }
37    }
38}