github.com/coveo/gotemplate@v2.7.7+incompatible/template/extra_math.go (about)

     1  package template
     2  
     3  import (
     4  	"math"
     5  )
     6  
     7  const (
     8  	mathBase         = "Mathematic Fundamental"
     9  	mathBits         = "Mathematic Bit Operations"
    10  	mathStatistics   = "Mathematic Stats"
    11  	mathTrigonometry = "Mathematic Trigonometry"
    12  	mathUtilities    = "Mathematic Utilities"
    13  )
    14  
    15  var mathBaseFuncs = dictionary{
    16  	"add":   add,
    17  	"ceil":  ceil,
    18  	"cbrt":  cbrt,
    19  	"dim":   dim,
    20  	"div":   divide,
    21  	"exp":   exp,
    22  	"exp2":  exp2,
    23  	"expm1": expm1,
    24  	"floor": floor,
    25  	"mod":   modulo,
    26  	"modf":  modf,
    27  	"mul":   multiply,
    28  	"pow":   power,
    29  	"pow10": power10,
    30  	"rem":   remainder,
    31  	"sub":   subtract,
    32  	"trunc": trunc,
    33  }
    34  
    35  var mathStatFuncs = dictionary{
    36  	"avg": average,
    37  	"max": max,
    38  	"min": min,
    39  }
    40  
    41  var mathTrigFuncs = dictionary{
    42  	"acos":   acos,
    43  	"acosh":  acosh,
    44  	"asin":   asin,
    45  	"asinh":  asinh,
    46  	"atan":   atan,
    47  	"atan2":  atan2,
    48  	"atanh":  atanh,
    49  	"cos":    cos,
    50  	"cosh":   cosh,
    51  	"deg":    deg,
    52  	"ilogb":  ilogb,
    53  	"j0":     j0,
    54  	"j1":     j1,
    55  	"jn":     jn,
    56  	"log":    logFunc,
    57  	"log10":  log10,
    58  	"log1p":  log1p,
    59  	"log2":   log2,
    60  	"logb":   logb,
    61  	"rad":    rad,
    62  	"sin":    sin,
    63  	"sincos": sincos,
    64  	"sinh":   sinh,
    65  	"tan":    tan,
    66  	"tanh":   tanh,
    67  	"y0":     y0,
    68  	"y1":     y1,
    69  	"yn":     yn,
    70  }
    71  
    72  var mathBitsFuncs = dictionary{
    73  	"band":   bitwiseAnd,
    74  	"bclear": bitwiseClear,
    75  	"bor":    bitwiseOr,
    76  	"bxor":   bitwiseXor,
    77  	"lshift": leftShift,
    78  	"rshift": rightShift,
    79  }
    80  
    81  var mathUtilFuncs = dictionary{
    82  	"abs":       abs,
    83  	"dec":       decimal,
    84  	"frexp":     frexp,
    85  	"gamma":     gamma,
    86  	"hex":       hex,
    87  	"hypot":     hypot,
    88  	"isInf":     isInfinity,
    89  	"isNaN":     isNaN,
    90  	"ldexp":     ldexp,
    91  	"lgamma":    lgamma,
    92  	"nextAfter": nextAfter,
    93  	"signBit":   signBit,
    94  	"sqrt":      sqrt,
    95  	"to":        to,
    96  	"until":     until,
    97  }
    98  
    99  var mathFuncsAliases = aliases{
   100  	"abs":    {"absolute"},
   101  	"acos":   {"arcCosine", "arcCosinus"},
   102  	"acosh":  {"arcHyperbolicCosine", "arcHyperbolicCosinus"},
   103  	"add":    {"sum"},
   104  	"asin":   {"arcSine", "arcSinus"},
   105  	"asinh":  {"arcHyperbolicSine", "arcHyperbolicSinus"},
   106  	"atan":   {"arcTangent"},
   107  	"atan2":  {"arcTangent2"},
   108  	"atanh":  {"arcHyperbolicTangent"},
   109  	"avg":    {"average"},
   110  	"band":   {"bitwiseAND"},
   111  	"bclear": {"bitwiseClear"},
   112  	"bor":    {"bitwiseOR"},
   113  	"bxor":   {"bitwiseXOR"},
   114  	"ceil":   {"roundUp", "roundup"},
   115  	"cos":    {"cosine", "cosinus"},
   116  	"cosh":   {"hyperbolicCosine", "hyperbolicCosinus"},
   117  	"dec":    {"decimal"},
   118  	"deg":    {"degree"},
   119  	"div":    {"divide", "quotient"},
   120  	"exp":    {"exponent"},
   121  	"exp2":   {"exponent2"},
   122  	"floor":  {"roundDown", "rounddown", "int", "integer"},
   123  	"hex":    {"hexa", "hexaDecimal"},
   124  	"hypot":  {"hypotenuse"},
   125  	"isInf":  {"isInfinity"},
   126  	"j0":     {"firstBessel0"},
   127  	"j1":     {"firstBessel1"},
   128  	"jn":     {"firstBesselN"},
   129  	"lshift": {"leftShift"},
   130  	"max":    {"maximum", "biggest"},
   131  	"min":    {"minimum", "smallest"},
   132  	"mod":    {"modulo"},
   133  	"mul":    {"multiply", "prod", "product"},
   134  	"pow":    {"power"},
   135  	"pow10":  {"power10"},
   136  	"rad":    {"radian"},
   137  	"rem":    {"remainder"},
   138  	"rshift": {"rightShift"},
   139  	"sin":    {"sine", "sinus"},
   140  	"sincos": {"sineCosine", "sinusCosinus"},
   141  	"sinh":   {"hyperbolicSine", "hyperbolicSinus"},
   142  	"sqrt":   {"squareRoot"},
   143  	"sub":    {"subtract"},
   144  	"tan":    {"tangent"},
   145  	"tanh":   {"hyperbolicTangent"},
   146  	"trunc":  {"truncate"},
   147  	"y0":     {"secondBessel0"},
   148  	"y1":     {"secondBessel1"},
   149  	"yn":     {"secondBesselN"},
   150  }
   151  
   152  var mathFuncsArgs = arguments{
   153  	"abs":             {"x"},
   154  	"acos":            {"x"},
   155  	"acosh":           {"x"},
   156  	"asin":            {"x"},
   157  	"asinh":           {"x"},
   158  	"atan":            {"x"},
   159  	"atan2":           {"x", "y"},
   160  	"atanh":           {"x"},
   161  	"cbrt":            {"x"},
   162  	"ceil":            {"x"},
   163  	"copysign":        {"x", "y"},
   164  	"cos":             {"x"},
   165  	"cosh":            {"x"},
   166  	"dim":             {"x", "y"},
   167  	"erf":             {"x"},
   168  	"erfc":            {"x"},
   169  	"exp":             {"x"},
   170  	"exp2":            {"x"},
   171  	"expm1":           {"x"},
   172  	"float32bits":     {"f"},
   173  	"float32frombits": {"b"},
   174  	"float64bits":     {"f"},
   175  	"float64frombits": {"b"},
   176  	"floor":           {"x"},
   177  	"frexp":           {"f"},
   178  	"gamma":           {"x"},
   179  	"hypot":           {"p", "q"},
   180  	"ilogb":           {"x"},
   181  	"inf":             {"sign"},
   182  	"isInf":           {"f"},
   183  	"isNaN":           {"f"},
   184  	"j0":              {"x"},
   185  	"j1":              {"x"},
   186  	"jn":              {"n", "x"},
   187  	"ldexp":           {"frac", "exp"},
   188  	"lgamma":          {"x"},
   189  	"log":             {"x"},
   190  	"log10":           {"x"},
   191  	"log1p":           {"x"},
   192  	"log2":            {"x"},
   193  	"logb":            {"x"},
   194  	"max":             {"x", "y"},
   195  	"min":             {"x", "y"},
   196  	"mod":             {"x", "y"},
   197  	"modf":            {"f"},
   198  	"nextafter":       {"x", "y"},
   199  	"nextafter32":     {"x", "y"},
   200  	"pow":             {"x", "y"},
   201  	"pow10":           {"n"},
   202  	"remainder":       {"x", "y"},
   203  	"signbit":         {"x"},
   204  	"sin":             {"x"},
   205  	"sincos":          {"x"},
   206  	"sinh":            {"x"},
   207  	"sqrt":            {"x"},
   208  	"tan":             {"x"},
   209  	"tanh":            {"x"},
   210  	"trunc":           {"x"},
   211  	"y0":              {"x"},
   212  	"y1":              {"x"},
   213  	"yn":              {"n", "x"},
   214  }
   215  
   216  var mathFuncsHelp = descriptions{
   217  	"abs":             "Returns the absolute value of x.\nSpecial cases are:\n    abs(±Inf) = +Inf\n    abs(NaN) = NaN",
   218  	"acos":            "Returns the arccosine, in radians, of x.\nSpecial case is:\n    acos(x) = NaN if x < -1 or x > 1",
   219  	"acosh":           "Returns the inverse hyperbolic cosine of x.\nSpecial cases are:\n    acosh(+Inf) = +Inf\n    acosh(x) = NaN if x < 1\n    acosh(NaN) = NaN",
   220  	"asin":            "Returns the arcsine, in radians, of x.\nSpecial cases are:\n    asin(±0) = ±0\n    asin(x) = NaN if x < -1 or x > 1",
   221  	"asinh":           "Returns the inverse hyperbolic sine of x.\nSpecial cases are:\n    asinh(±0) = ±0\n    asinh(±Inf) = ±Inf\n    asinh(NaN) = NaN",
   222  	"atan":            "Returns the arctangent, in radians, of x.\nSpecial cases are:\n    atan(±0) = ±0\n    atan(±Inf) = ±Pi/2",
   223  	"atan2":           "Returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.\nSpecial cases are (in order):\n    atan2(y, NaN) = NaN\n    atan2(NaN, x) = NaN\n    atan2(+0, x>=0) = +0\n    atan2(-0, x>=0) = -0\n    atan2(+0, x<=-0) = +Pi\n    atan2(-0, x<=-0) = -Pi\n    atan2(y>0, 0) = +Pi/2\n    atan2(y<0, 0) = -Pi/2\n    atan2(+Inf, +Inf) = +Pi/4\n    atan2(-Inf, +Inf) = -Pi/4\n    atan2(+Inf, -Inf) = 3Pi/4\n    atan2(-Inf, -Inf) = -3Pi/4\n    atan2(y, +Inf) = 0\n    atan2(y>0, -Inf) = +Pi\n    atan2(y<0, -Inf) = -Pi\n    atan2(+Inf, x) = +Pi/2\n    atan2(-Inf, x) = -Pi/2",
   224  	"atanh":           "Returns the inverse hyperbolic tangent of x.\nSpecial cases are:\n    atanh(1) = +Inf\n    atanh(±0) = ±0\n    atanh(-1) = -Inf\n    atanh(x) = NaN if x < -1 or x > 1\n    atanh(NaN) = NaN",
   225  	"cbrt":            "Returns the cube root of x.\nSpecial cases are:\n    cbrt(±0) = ±0\n    cbrt(±Inf) = ±Inf\n    cbrt(NaN) = NaN",
   226  	"ceil":            "Returns the least integer value greater than or equal to x.\nSpecial cases are:\n    ceil(±0) = ±0\n    ceil(±Inf) = ±Inf\n    ceil(NaN) = NaN",
   227  	"copysign":        "Returns a value with the magnitude of x and the sign of y",
   228  	"cos":             "Returns the cosine of the radian argument x.\nSpecial cases are:\n    cos(±Inf) = NaN\n    cos(NaN) = NaN",
   229  	"cosh":            "Returns the hyperbolic cosine of x.\nSpecial cases are:\n    cosh(±0) = 1\n    cosh(±Inf) = +Inf\n    cosh(NaN) = NaN",
   230  	"dim":             "Returns the maximum of x-y or 0.\nSpecial cases are:\n    dim(+Inf, +Inf) = NaN\n    dim(-Inf, -Inf) = NaN\n    dim(x, NaN) = dim(NaN, x) = NaN",
   231  	"erf":             "Returns the error function of x.\nSpecial cases are:\n    Erf(+Inf) = 1\nErf(-Inf) = -1\nErf(NaN) = NaN",
   232  	"erfc":            "Returns the complementary error function of x.\nSpecial cases are:\n    Erfc(+Inf) = 0\nErfc(-Inf) = 2\nErfc(NaN) = NaN",
   233  	"exp":             "Returns e**x, the base-e exponential of x.\nSpecial cases are:\n    exp(+Inf) = +Inf\n    exp(NaN) = NaN\nVery large values overflow to 0 or +Inf. Very small values underflow to 1.",
   234  	"exp2":            "Returns 2**x, the base-2 exponential of x.\nSpecial cases are the same as exp.",
   235  	"expm1":           "Returns e**x - 1, the base-e exponential of x minus 1. It is more\naccurate than exp(x) - 1 when x is near zero.\nSpecial cases are:\n    expm1(+Inf) = +Inf\n    expm1(-Inf) = -1\n    expm1(NaN) = NaN\nVery large values overflow to -1 or +Inf",
   236  	"float32bits":     "Returns the IEEE 754 binary representation of f",
   237  	"float32frombits": "Returns the floating point number corresponding to the\nIEEE 754 binary representation b",
   238  	"float64bits":     "Returns the IEEE 754 binary representation of f",
   239  	"float64frombits": "Returns the floating point number corresponding the IEEE\n754 binary representation b",
   240  	"floor":           "Returns the greatest integer value less than or equal to x.\nSpecial cases are:\n    floor(±0) = ±0\n    floor(±Inf) = ±Inf\n    floor(NaN) = NaN",
   241  	"frexp":           "Breaks f into a normalized fraction and an integral power of two. Returns frac and exp satisfying f == frac × 2**exp, with the absolute value of frac in the interval [½, 1).\nSpecial cases are:\n    frexp(±0) = ±0, 0\n    frexp(±Inf) = ±Inf, 0\n    frexp(NaN) = NaN, 0",
   242  	"gamma":           "Returns the Gamma function of x.\nSpecial cases are:\n    gamma(+Inf) = +Inf\n    gamma(+0) = +Inf\n    gamma(-0) = -Inf\n    gamma(x) = NaN for integer x < 0\n    gamma(-Inf) = NaN\n    gamma(NaN) = NaN",
   243  	"hypot":           "Returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.\nSpecial cases are:\n    hypot(±Inf, q) = +Inf\n    hypot(p, ±Inf) = +Inf\n    hypot(NaN, q) = NaN\n    hypot(p, NaN) = NaN",
   244  	"ilogb":           "Returns the binary exponent of x as an integer.\nSpecial cases are:\n    ilogb(±Inf) = MaxInt32\n    ilogb(0) = MinInt32\n    ilogb(NaN) = MaxInt32",
   245  	"inf":             "Returns positive infinity if sign >= 0, negative infinity if sign <\n0",
   246  	"isInf":           "Reports whether f is an infinity, according to sign. If sign > 0, isInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity",
   247  	"isNaN":           "Reports whether f is an IEEE 754 'not-a-number' value",
   248  	"j0":              "Returns the order-zero Bessel function of the first kind.\nSpecial cases are:\n    j0(±Inf) = 0\n    j0(0) = 1\n    j0(NaN) = NaN",
   249  	"j1":              "Returns the order-one Bessel function of the first kind.\nSpecial cases are:\n    j1(±Inf) = 0\n    j1(NaN) = NaN",
   250  	"jn":              "Returns the order-n Bessel function of the first kind.\nSpecial cases are:\n    jn(n, ±Inf) = 0\n    jn(n, NaN) = NaN",
   251  	"ldexp":           "Ldexp is the inverse of Frexp. Returns frac × 2**exp.\nSpecial cases are:\n    ldexp(±0, exp) = ±0\n    ldexp(±Inf, exp) = ±Inf\n    ldexp(NaN, exp) = NaN",
   252  	"lgamma":          "Returns the natural logarithm and sign (-1 or +1) of Gamma(x).\nSpecial cases are:\n    lgamma(+Inf) = +Inf\n    lgamma(0) = +Inf\n    lgamma(-integer) = +Inf\n    lgamma(-Inf) = -Inf\n    lgamma(NaN) = NaN",
   253  	"log":             "Returns the natural logarithm of x.\nSpecial cases are:\n    log(+Inf) = +Inf\n    log(0) = -Inf\n    log(x < 0) = NaN\n    log(NaN) = NaN",
   254  	"log10":           "Returns the decimal logarithm of x. The special cases are the same as for log.",
   255  	"log1p":           "Returns the natural logarithm of 1 plus its argument x. It is more accurate than log(1 + x) when x is near zero.\nSpecial cases are:\n    log1p(+Inf) = +Inf\n    log1p(±0) = ±0\n    log1p(-1) = -Inf\n    log1p(x < -1) = NaN\n    log1p(NaN) = NaN",
   256  	"log2":            "Returns the binary logarithm of x. The special cases are the same as for log.",
   257  	"logb":            "Returns the binary exponent of x.\nSpecial cases are:\n    logb(±Inf) = +Inf\n    logb(0) = -Inf\n    logb(NaN) = NaN",
   258  	"max":             "Returns the larger of x or y.\nSpecial cases are:\n    max(x, +Inf) = max(+Inf, x) = +Inf\n    max(x, NaN) = max(NaN, x) = NaN\n    max(+0, ±0) = max(±0, +0) = +0\n    max(-0, -0) = -0",
   259  	"min":             "Returns the smaller of x or y.\nSpecial cases are:\n    min(x, -Inf) = min(-Inf, x) = -Inf\n    min(x, NaN) = min(NaN, x) = NaN\n    min(-0, ±0) = min(±0, -0) = -0",
   260  	"mod":             "Returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.\nSpecial cases are:\n    mod(±Inf, y) = NaN\n    mod(NaN, y) = NaN\n    mod(x, 0) = NaN\n    mod(x, ±Inf) = x\n    mod(x, NaN) = NaN",
   261  	"modf":            "Returns integer and fractional floating-point numbers that sum to f. Both values have the same sign as f.\nSpecial cases are:\n    modf(±Inf) = ±Inf, NaN\n    modf(NaN) = NaN, NaN",
   262  	"naN":             "Returns an IEEE 754 'not-a-number' value.",
   263  	"nextAfter":       "Returns the next representable float64 value after x towards y.\nSpecial cases are:\n    Nextafter(x, x)   = x\nNextafter(NaN, y) = NaN\nNextafter(x, NaN) = NaN",
   264  	"nextAfter32":     "Returns the next representable float32 value after x towards y.\nSpecial cases are:\n    Nextafter32(x, x)   = x\nNextafter32(NaN, y) = NaN\nNextafter32(x, NaN) = NaN",
   265  	"pow":             "Returns x**y, the base-x exponential of y.\nSpecial cases are (in order):\n    pow(x, ±0) = 1 for any x\n    pow(1, y) = 1 for any y\n    pow(x, 1) = x for any x\n    pow(NaN, y) = NaN\n    pow(x, NaN) = NaN\n    pow(±0, y) = ±Inf for y an odd integer < 0\n    pow(±0, -Inf) = +Inf\n    pow(±0, +Inf) = +0\n    pow(±0, y) = +Inf for finite y < 0 and not an odd integer\n    pow(±0, y) = ±0 for y an odd integer > 0\n    pow(±0, y) = +0 for finite y > 0 and not an odd integer\n    pow(-1, ±Inf) = 1\n    pow(x, +Inf) = +Inf for |x| > 1\n    pow(x, -Inf) = +0 for |x| > 1\n    pow(x, +Inf) = +0 for |x| < 1\n    pow(x, -Inf) = +Inf for |x| < 1\n    pow(+Inf, y) = +Inf for y > 0\n    pow(+Inf, y) = +0 for y < 0\n    pow(-Inf, y) = Pow(-0, -y)\n    pow(x, y) = NaN for finite x < 0 and finite non-integer y",
   266  	"pow10":           "Returns 10**n, the base-10 exponential of n.\nSpecial cases are:\n    pow10(n) =0 for n < -323\n    pow10(n) = +Inf for n > 308",
   267  	"rem":             "Returns the IEEE 754 floating-point remainder of x/y.\nSpecial cases are:\n    rem(±Inf, y) = NaN\n    rem(NaN, y) = NaN\n    rem(x, 0) = NaN\n    rem(x, ±Inf) = x\n    rem(x, NaN) = NaN",
   268  	"signbit":         "Returns true if x is negative or negative zero",
   269  	"sin":             "Returns the sine of the radian argument x.\nSpecial cases are:\n    sin(±0) = ±0\n    sin(±Inf) = NaN\n    sin(NaN) = NaN",
   270  	"sincos":          "Returns Sin(x), Cos(x).\nSpecial cases are:\n    sincos(±0) = ±0, 1\n    sincos(±Inf) = NaN, NaN\n    sincos(NaN) = NaN, NaN",
   271  	"sinh":            "Returns the hyperbolic sine of x.\nSpecial cases are:\n    sinh(±0) = ±0\n    sinh(±Inf) = ±Inf\n    sinh(NaN) = NaN",
   272  	"sqrt":            "Returns the square root of x.\nSpecial cases are:\n    sqrt(+Inf) = +Inf\n    sqrt(±0) = ±0\n    sqrt(x < 0) = NaN\n    sqrt(NaN) = NaN",
   273  	"tan":             "Returns the tangent of the radian argument x.\nSpecial cases are:\n    tan(±0) = ±0\n    tan(±Inf) = NaN\n    tan(NaN) = NaN",
   274  	"tanh":            "Returns the hyperbolic tangent of x.\nSpecial cases are:\n    tanh(±0) = ±0\n    tanh(±Inf) = ±1\n    tanh(NaN) = NaN",
   275  	"trunc":           "Returns the integer value of x.\nSpecial cases are:\n    trunc(±0) = ±0\n    trunc(±Inf) = ±Inf\n    trunc(NaN) = NaN",
   276  	"y0":              "Returns the order-zero Bessel function of the second kind.\nSpecial cases are:\n    y0(+Inf) = 0\n    y0(0) = -Inf\n    y0(x < 0) = NaN\n    y0(NaN) = NaN",
   277  	"y1":              "Returns the order-one Bessel function of the second kind.\nSpecial cases are:\n    y1(+Inf) = 0\n    y1(0) = -Inf\n    y1(x < 0) = NaN\n    y1(NaN) = NaN",
   278  	"yn":              "Returns the order-n Bessel function of the second kind.\nSpecial cases are:\n    yn(n, +Inf) = 0\n    yn(n ≥ 0, 0) = -Inf\n    yn(n < 0, 0) = +Inf if n is odd, -Inf if n is even\n    yn(n, x < 0) = NaN\n    yn(n, NaN) = NaN",
   279  }
   280  
   281  func (t *Template) addMathFuncs() {
   282  	// Enhance mathematic functions
   283  	options := FuncOptions{
   284  		FuncHelp:    mathFuncsHelp,
   285  		FuncArgs:    mathFuncsArgs,
   286  		FuncAliases: mathFuncsAliases,
   287  	}
   288  
   289  	t.AddFunctions(mathBaseFuncs, mathBase, options)
   290  	t.AddFunctions(mathStatFuncs, mathStatistics, options)
   291  	t.AddFunctions(mathTrigFuncs, mathTrigonometry, options)
   292  	t.AddFunctions(mathBitsFuncs, mathBits, options)
   293  	t.AddFunctions(mathUtilFuncs, mathUtilities, options)
   294  
   295  	constants := dictionary{
   296  		"E":                      math.E,
   297  		"Pi":                     math.Pi,
   298  		"Phi":                    math.Phi,
   299  		"Sqrt2":                  math.Sqrt2,
   300  		"SqrtE":                  math.SqrtE,
   301  		"SqrtPi":                 math.SqrtPi,
   302  		"SqrtPhi":                math.SqrtPhi,
   303  		"Ln2":                    math.Ln2,
   304  		"Log2E":                  math.Log2E,
   305  		"Ln10":                   math.Ln10,
   306  		"Log10E":                 math.Log10E,
   307  		"MaxFloat32":             math.MaxFloat32,
   308  		"MaxFloat64":             math.MaxFloat64,
   309  		"SmallestNonzeroFloat64": math.SmallestNonzeroFloat64,
   310  		"MaxInt8":                math.MaxInt8,
   311  		"MaxInt16":               math.MaxInt16,
   312  		"MaxInt32":               math.MaxInt32,
   313  		"MaxUint8":               math.MaxUint8,
   314  		"MaxUint16":              math.MaxUint16,
   315  		"MaxUint32":              math.MaxUint32,
   316  		// Those values are commented because they causes problem with object serialization.
   317  		// "MaxInt64":            math.MaxInt64,
   318  		// "MaxUint64":           uint(math.MaxUint64),
   319  		// "Nan":                 math.NaN(),
   320  		// "Infinity":            math.Inf(1),
   321  		// "Inf":                 math.Inf(1),
   322  		// "NegativeInfinity":    math.Inf(-1),
   323  		// "NegInf":              math.Inf(-1),
   324  	}
   325  
   326  	// We do not want to inject the math constant twice
   327  	if !t.optionsEnabled[Math] {
   328  		t.setConstant(true, constants, "Math", "MATH")
   329  		t.optionsEnabled[Math] = true
   330  	}
   331  }
   332  
   333  func to(params ...interface{}) (interface{}, error)    { return generateNumericArray(true, params...) }
   334  func until(params ...interface{}) (interface{}, error) { return generateNumericArray(false, params...) }
   335  
   336  func abs(a interface{}) (r interface{}, err error) {
   337  	defer func() { err = trapError(err, recover()) }()
   338  	return processFloat(a, math.Abs)
   339  }
   340  
   341  func cbrt(a interface{}) (r interface{}, err error) {
   342  	defer func() { err = trapError(err, recover()) }()
   343  	return processFloat(a, math.Cbrt)
   344  }
   345  
   346  func ceil(a interface{}) (r interface{}, err error) {
   347  	defer func() { err = trapError(err, recover()) }()
   348  	return processFloat(a, math.Ceil)
   349  }
   350  
   351  // math.Copysign
   352  
   353  func dim(a, b interface{}) (r interface{}, err error) {
   354  	defer func() { err = trapError(err, recover()) }()
   355  	return processFloat2(a, b, math.Dim)
   356  }
   357  
   358  // math.Erf
   359  // math.Erfc
   360  
   361  func exp(a interface{}) (r interface{}, err error) {
   362  	defer func() { err = trapError(err, recover()) }()
   363  	return processFloat(a, math.Exp)
   364  }
   365  
   366  func exp2(a interface{}) (r interface{}, err error) {
   367  	defer func() { err = trapError(err, recover()) }()
   368  	return processFloat(a, math.Exp2)
   369  }
   370  
   371  func expm1(a interface{}) (r interface{}, err error) {
   372  	defer func() { err = trapError(err, recover()) }()
   373  	return processFloat(a, math.Expm1)
   374  }
   375  
   376  func floor(a interface{}) (r interface{}, err error) {
   377  	defer func() { err = trapError(err, recover()) }()
   378  	return processFloat(a, math.Floor)
   379  }
   380  
   381  func frexp(a interface{}) (r interface{}, err error) {
   382  	defer func() { err = trapError(err, recover()) }()
   383  	f, e := math.Frexp(toFloat(a))
   384  	return []interface{}{simplify(f), e}, nil
   385  }
   386  
   387  func gamma(a interface{}) (r interface{}, err error) {
   388  	defer func() { err = trapError(err, recover()) }()
   389  	return processFloat(a, math.Gamma)
   390  }
   391  
   392  func infinity(a interface{}) (r interface{}, err error) {
   393  	defer func() { err = trapError(err, recover()) }()
   394  	return simplify(math.Inf(toInt(a))), nil
   395  }
   396  
   397  func isInfinity(a, b interface{}) (r interface{}, err error) {
   398  	defer func() { err = trapError(err, recover()) }()
   399  	return math.IsInf(toFloat(a), toInt(b)), nil
   400  }
   401  
   402  func isNaN(a interface{}) (r interface{}, err error) {
   403  	defer func() { err = trapError(err, recover()) }()
   404  	return math.IsNaN(toFloat(a)), nil
   405  }
   406  
   407  func j0(a interface{}) (r interface{}, err error) {
   408  	defer func() { err = trapError(err, recover()) }()
   409  	return processFloat(a, math.J0)
   410  }
   411  
   412  func j1(a interface{}) (r interface{}, err error) {
   413  	defer func() { err = trapError(err, recover()) }()
   414  	return processFloat(a, math.J1)
   415  }
   416  
   417  func jn(n, x interface{}) (r interface{}, err error) {
   418  	defer func() { err = trapError(err, recover()) }()
   419  	return math.Jn(toInt(n), toFloat(x)), nil
   420  }
   421  
   422  func ldexp(a, b interface{}) (r interface{}, err error) {
   423  	defer func() { err = trapError(err, recover()) }()
   424  	return simplify(math.Ldexp(toFloat(a), toInt(b))), nil
   425  }
   426  
   427  func lgamma(a interface{}) (r interface{}, err error) {
   428  	defer func() { err = trapError(err, recover()) }()
   429  	f, e := math.Lgamma(toFloat(a))
   430  	return []interface{}{simplify(f), e}, nil
   431  }
   432  
   433  func nextAfter(a, b interface{}) (r interface{}, err error) {
   434  	defer func() { err = trapError(err, recover()) }()
   435  	return simplify(math.Nextafter(toFloat(a), toFloat(b))), nil
   436  }
   437  
   438  func remainder(a, b interface{}) (r interface{}, err error) {
   439  	defer func() { err = trapError(err, recover()) }()
   440  	return simplify(math.Remainder(toFloat(a), toFloat(b))), nil
   441  }
   442  
   443  func signBit(a, b interface{}) (r interface{}, err error) {
   444  	defer func() { err = trapError(err, recover()) }()
   445  	return math.Signbit(toFloat(a)), nil
   446  }
   447  
   448  func sqrt(a interface{}) (r interface{}, err error) {
   449  	defer func() { err = trapError(err, recover()) }()
   450  	return processFloat(a, math.Sqrt)
   451  }
   452  
   453  func trunc(a interface{}) (r interface{}, err error) {
   454  	defer func() { err = trapError(err, recover()) }()
   455  	return processFloat(a, math.Trunc)
   456  }
   457  
   458  func y0(a interface{}) (r interface{}, err error) {
   459  	defer func() { err = trapError(err, recover()) }()
   460  	return processFloat(a, math.Y0)
   461  }
   462  
   463  func y1(a interface{}) (r interface{}, err error) {
   464  	defer func() { err = trapError(err, recover()) }()
   465  	return processFloat(a, math.Y1)
   466  }
   467  
   468  func yn(n, x interface{}) (r interface{}, err error) {
   469  	defer func() { err = trapError(err, recover()) }()
   470  	return math.Yn(toInt(n), toFloat(x)), nil
   471  }