aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/grouping/request/MathFunctions.java
blob: d76c464a6de3d514740ba18b357219d6e9c48d5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.request;

/**
 * @author baldersheim
 */
public abstract class MathFunctions {

    /**
     * Defines the different types of math functions that are available.
     */
    public enum Function {
        EXP,     //  0
        POW,     //  1
        LOG,     //  2
        LOG1P,   //  3
        LOG10,   //  4
        SIN,     //  5
        ASIN,    //  6
        COS,     //  7
        ACOS,    //  8
        TAN,     //  9
        ATAN,    // 10
        SQRT,    // 11
        SINH,    // 12
        ASINH,   // 13
        COSH,    // 14
        ACOSH,   // 15
        TANH,    // 16
        ATANH,   // 17
        CBRT,    // 18
        HYPOT,   // 19
        FLOOR;   // 20

        static Function create(int tid) {
            for(Function p : values()) {
                if (tid == p.ordinal()) {
                    return p;
                }
            }
            return null;
        }
    }
    public static FunctionNode newInstance(Function type, GroupingExpression x, GroupingExpression y) {
        return switch (type) {
            case EXP -> new MathExpFunction(x);
            case POW -> new MathPowFunction(x, y);
            case LOG -> new MathLogFunction(x);
            case LOG1P -> new MathLog1pFunction(x);
            case LOG10 -> new MathLog10Function(x);
            case SIN -> new MathSinFunction(x);
            case ASIN -> new MathASinFunction(x);
            case COS -> new MathCosFunction(x);
            case ACOS -> new MathACosFunction(x);
            case TAN -> new MathTanFunction(x);
            case ATAN -> new MathATanFunction(x);
            case SQRT -> new MathSqrtFunction(x);
            case SINH -> new MathSinHFunction(x);
            case ASINH -> new MathASinHFunction(x);
            case COSH -> new MathCosHFunction(x);
            case ACOSH -> new MathACosHFunction(x);
            case TANH -> new MathTanHFunction(x);
            case ATANH -> new MathATanHFunction(x);
            case CBRT -> new MathCbrtFunction(x);
            case HYPOT -> new MathHypotFunction(x, y);
            case FLOOR -> new MathFloorFunction(x);
        };
    }
}