<commit_before>#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "mapper_internal.h"

#define STACK_SIZE 256
#ifdef DEBUG
#define TRACING 0 /* Set non-zero to see trace during parse & eval. */
#else
#define TRACING 0
#endif

static float minf(float x, float y)
{
    if (y < x) return y;
    else return x;
}

static float maxf(float x, float y)
{
    if (y > x) return y;
    else return x;
}

static float pif()
{
    return M_PI;
}

typedef enum {
    FUNC_UNKNOWN=-1,
    FUNC_POW=0,
    FUNC_SIN,
    FUNC_COS,
    FUNC_TAN,
    FUNC_ABS,
    FUNC_SQRT,
    FUNC_LOG,
    FUNC_LOG10,
    FUNC_EXP,
    FUNC_FLOOR,
    FUNC_ROUND,
    FUNC_CEIL,
    FUNC_ASIN,
    FUNC_ACOS,
    FUNC_ATAN,
    FUNC_ATAN2,
    FUNC_SINH,
    FUNC_COSH,
    FUNC_TANH,
    FUNC_LOGB,
    FUNC_EXP2,
    FUNC_LOG2,
    FUNC_HYPOT,
    FUNC_CBRT,
    FUNC_TRUNC,
    FUNC_MIN,
    FUNC_MAX,
    FUNC_PI,
    N_FUNCS
} expr_func_t;

static struct {
    const char *name;
    unsigned int arity;
    void *func;
} function_table[] = {
    { "pow", 2, powf },
    { "sin", 1, sinf },
    { "cos", 1, cosf },
    { "tan", 1, tanf },
    { "abs", 1, fabsf },
    { "sqrt", 1, sqrtf },
    { "log", 1, logf },
    { "log10", 1, log10f },
    { "exp", 1, expf },
    { "floor", 1, floorf },
    { "round", 1, roundf },
    { "ceil", 1, ceilf },
    { "asin", 1, asinf },
    { "acos", 1, acosf },
    { "atan", 1, atanf },
    { "atan2", 2, atan2f },
    { "sinh", 1, sinhf },
    { "cosh", 1, coshf },
    { "tanh", 1, tanhf },
    { "logb", 1, logbf },
    { "exp2", 1, exp2f },
    { "log2", 1, log2f },
    { "hypot", 2, hypotf },
    { "cbrt", 1, cbrtf },
    { "trunc", 1, truncf },
    { "min", 2, minf },
    { "max", 2, maxf },
    { "pi", 0, pif },
};

typedef float func_float_arity0();
typedef float func_float_arity1(float);
typedef float func_float_arity2(float,float);

typedef struct _token {<commit_msg>Added functions midi2hz() and hz2midi() to expression parser.<commit_after>#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "mapper_internal.h"

#define STACK_SIZE 256
#ifdef DEBUG
#define TRACING 0 /* Set non-zero to see trace during parse & eval. */
#else
#define TRACING 0
#endif

static float minf(float x, float y)
{
    if (y < x) return y;
    else return x;
}

static float maxf(float x, float y)
{
    if (y > x) return y;
    else return x;
}

static float pif()
{
    return M_PI;
}

static float midi2hz(float x)
{
    return 440. * pow(2.0, (x - 69) / 12.0);
}

static float hz2midi(float x)
{
    return 69. + 12. * log2(x / 440.);
}

typedef enum {
    FUNC_UNKNOWN=-1,
    FUNC_POW=0,
    FUNC_SIN,
    FUNC_COS,
    FUNC_TAN,
    FUNC_ABS,
    FUNC_SQRT,
    FUNC_LOG,
    FUNC_LOG10,
    FUNC_EXP,
    FUNC_FLOOR,
    FUNC_ROUND,
    FUNC_CEIL,
    FUNC_ASIN,
    FUNC_ACOS,
    FUNC_ATAN,
    FUNC_ATAN2,
    FUNC_SINH,
    FUNC_COSH,
    FUNC_TANH,
    FUNC_LOGB,
    FUNC_EXP2,
    FUNC_LOG2,
    FUNC_HYPOT,
    FUNC_CBRT,
    FUNC_TRUNC,
    FUNC_MIN,
    FUNC_MAX,
    FUNC_PI,
    FUNC_MIDI2HZ,
    FUNC_HZ2MIDI,
    N_FUNCS
} expr_func_t;

static struct {
    const char *name;
    unsigned int arity;
    void *func;
} function_table[] = {
    { "pow", 2, powf },
    { "sin", 1, sinf },
    { "cos", 1, cosf },
    { "tan", 1, tanf },
    { "abs", 1, fabsf },
    { "sqrt", 1, sqrtf },
    { "log", 1, logf },
    { "log10", 1, log10f },
    { "exp", 1, expf },
    { "floor", 1, floorf },
    { "round", 1, roundf },
    { "ceil", 1, ceilf },
    { "asin", 1, asinf },
    { "acos", 1, acosf },
    { "atan", 1, atanf },
    { "atan2", 2, atan2f },
    { "sinh", 1, sinhf },
    { "cosh", 1, coshf },
    { "tanh", 1, tanhf },
    { "logb", 1, logbf },
    { "exp2", 1, exp2f },
    { "log2", 1, log2f },
    { "hypot", 2, hypotf },
    { "cbrt", 1, cbrtf },
    { "trunc", 1, truncf },
    { "min", 2, minf },
    { "max", 2, maxf },
    { "pi", 0, pif },
    { "midi2hz", 1, midi2hz },
    { "hz2midi", 1, hz2midi },
};

typedef float func_float_arity0();
typedef float func_float_arity1(float);
typedef float func_float_arity2(float,float);

typedef struct _token {
{'fraction_non_alphanumeric': 0.16397338403041825, 'fraction_numerical': 0.03231939163498099, 'mean_word_length': 2.4699093157460843, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3693709', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1799, 'n_words': 446}