1
0

math.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package stdlib
  2. import (
  3. "math"
  4. "github.com/d5/tengo/v2"
  5. )
  6. var mathModule = map[string]tengo.Object{
  7. "e": tengo.Float{Value: math.E},
  8. "pi": tengo.Float{Value: math.Pi},
  9. "phi": tengo.Float{Value: math.Phi},
  10. "sqrt2": tengo.Float{Value: math.Sqrt2},
  11. "sqrtE": tengo.Float{Value: math.SqrtE},
  12. "sqrtPi": tengo.Float{Value: math.SqrtPi},
  13. "sqrtPhi": tengo.Float{Value: math.SqrtPhi},
  14. "ln2": tengo.Float{Value: math.Ln2},
  15. "log2E": tengo.Float{Value: math.Log2E},
  16. "ln10": tengo.Float{Value: math.Ln10},
  17. "log10E": tengo.Float{Value: math.Log10E},
  18. "abs": &tengo.UserFunction{
  19. Name: "abs",
  20. Value: FuncAFRF(math.Abs),
  21. },
  22. "acos": &tengo.UserFunction{
  23. Name: "acos",
  24. Value: FuncAFRF(math.Acos),
  25. },
  26. "acosh": &tengo.UserFunction{
  27. Name: "acosh",
  28. Value: FuncAFRF(math.Acosh),
  29. },
  30. "asin": &tengo.UserFunction{
  31. Name: "asin",
  32. Value: FuncAFRF(math.Asin),
  33. },
  34. "asinh": &tengo.UserFunction{
  35. Name: "asinh",
  36. Value: FuncAFRF(math.Asinh),
  37. },
  38. "atan": &tengo.UserFunction{
  39. Name: "atan",
  40. Value: FuncAFRF(math.Atan),
  41. },
  42. "atan2": &tengo.UserFunction{
  43. Name: "atan2",
  44. Value: FuncAFFRF(math.Atan2),
  45. },
  46. "atanh": &tengo.UserFunction{
  47. Name: "atanh",
  48. Value: FuncAFRF(math.Atanh),
  49. },
  50. "cbrt": &tengo.UserFunction{
  51. Name: "cbrt",
  52. Value: FuncAFRF(math.Cbrt),
  53. },
  54. "ceil": &tengo.UserFunction{
  55. Name: "ceil",
  56. Value: FuncAFRF(math.Ceil),
  57. },
  58. "copysign": &tengo.UserFunction{
  59. Name: "copysign",
  60. Value: FuncAFFRF(math.Copysign),
  61. },
  62. "cos": &tengo.UserFunction{
  63. Name: "cos",
  64. Value: FuncAFRF(math.Cos),
  65. },
  66. "cosh": &tengo.UserFunction{
  67. Name: "cosh",
  68. Value: FuncAFRF(math.Cosh),
  69. },
  70. "dim": &tengo.UserFunction{
  71. Name: "dim",
  72. Value: FuncAFFRF(math.Dim),
  73. },
  74. "erf": &tengo.UserFunction{
  75. Name: "erf",
  76. Value: FuncAFRF(math.Erf),
  77. },
  78. "erfc": &tengo.UserFunction{
  79. Name: "erfc",
  80. Value: FuncAFRF(math.Erfc),
  81. },
  82. "exp": &tengo.UserFunction{
  83. Name: "exp",
  84. Value: FuncAFRF(math.Exp),
  85. },
  86. "exp2": &tengo.UserFunction{
  87. Name: "exp2",
  88. Value: FuncAFRF(math.Exp2),
  89. },
  90. "expm1": &tengo.UserFunction{
  91. Name: "expm1",
  92. Value: FuncAFRF(math.Expm1),
  93. },
  94. "floor": &tengo.UserFunction{
  95. Name: "floor",
  96. Value: FuncAFRF(math.Floor),
  97. },
  98. "gamma": &tengo.UserFunction{
  99. Name: "gamma",
  100. Value: FuncAFRF(math.Gamma),
  101. },
  102. "hypot": &tengo.UserFunction{
  103. Name: "hypot",
  104. Value: FuncAFFRF(math.Hypot),
  105. },
  106. "ilogb": &tengo.UserFunction{
  107. Name: "ilogb",
  108. Value: FuncAFRI(math.Ilogb),
  109. },
  110. "inf": &tengo.UserFunction{
  111. Name: "inf",
  112. Value: FuncAIRF(math.Inf),
  113. },
  114. "is_inf": &tengo.UserFunction{
  115. Name: "is_inf",
  116. Value: FuncAFIRB(math.IsInf),
  117. },
  118. "is_nan": &tengo.UserFunction{
  119. Name: "is_nan",
  120. Value: FuncAFRB(math.IsNaN),
  121. },
  122. "j0": &tengo.UserFunction{
  123. Name: "j0",
  124. Value: FuncAFRF(math.J0),
  125. },
  126. "j1": &tengo.UserFunction{
  127. Name: "j1",
  128. Value: FuncAFRF(math.J1),
  129. },
  130. "jn": &tengo.UserFunction{
  131. Name: "jn",
  132. Value: FuncAIFRF(math.Jn),
  133. },
  134. "ldexp": &tengo.UserFunction{
  135. Name: "ldexp",
  136. Value: FuncAFIRF(math.Ldexp),
  137. },
  138. "log": &tengo.UserFunction{
  139. Name: "log",
  140. Value: FuncAFRF(math.Log),
  141. },
  142. "log10": &tengo.UserFunction{
  143. Name: "log10",
  144. Value: FuncAFRF(math.Log10),
  145. },
  146. "log1p": &tengo.UserFunction{
  147. Name: "log1p",
  148. Value: FuncAFRF(math.Log1p),
  149. },
  150. "log2": &tengo.UserFunction{
  151. Name: "log2",
  152. Value: FuncAFRF(math.Log2),
  153. },
  154. "logb": &tengo.UserFunction{
  155. Name: "logb",
  156. Value: FuncAFRF(math.Logb),
  157. },
  158. "max": &tengo.UserFunction{
  159. Name: "max",
  160. Value: FuncAFFRF(math.Max),
  161. },
  162. "min": &tengo.UserFunction{
  163. Name: "min",
  164. Value: FuncAFFRF(math.Min),
  165. },
  166. "mod": &tengo.UserFunction{
  167. Name: "mod",
  168. Value: FuncAFFRF(math.Mod),
  169. },
  170. "nan": &tengo.UserFunction{
  171. Name: "nan",
  172. Value: FuncARF(math.NaN),
  173. },
  174. "nextafter": &tengo.UserFunction{
  175. Name: "nextafter",
  176. Value: FuncAFFRF(math.Nextafter),
  177. },
  178. "pow": &tengo.UserFunction{
  179. Name: "pow",
  180. Value: FuncAFFRF(math.Pow),
  181. },
  182. "pow10": &tengo.UserFunction{
  183. Name: "pow10",
  184. Value: FuncAIRF(math.Pow10),
  185. },
  186. "remainder": &tengo.UserFunction{
  187. Name: "remainder",
  188. Value: FuncAFFRF(math.Remainder),
  189. },
  190. "signbit": &tengo.UserFunction{
  191. Name: "signbit",
  192. Value: FuncAFRB(math.Signbit),
  193. },
  194. "sin": &tengo.UserFunction{
  195. Name: "sin",
  196. Value: FuncAFRF(math.Sin),
  197. },
  198. "sinh": &tengo.UserFunction{
  199. Name: "sinh",
  200. Value: FuncAFRF(math.Sinh),
  201. },
  202. "sqrt": &tengo.UserFunction{
  203. Name: "sqrt",
  204. Value: FuncAFRF(math.Sqrt),
  205. },
  206. "tan": &tengo.UserFunction{
  207. Name: "tan",
  208. Value: FuncAFRF(math.Tan),
  209. },
  210. "tanh": &tengo.UserFunction{
  211. Name: "tanh",
  212. Value: FuncAFRF(math.Tanh),
  213. },
  214. "trunc": &tengo.UserFunction{
  215. Name: "trunc",
  216. Value: FuncAFRF(math.Trunc),
  217. },
  218. "y0": &tengo.UserFunction{
  219. Name: "y0",
  220. Value: FuncAFRF(math.Y0),
  221. },
  222. "y1": &tengo.UserFunction{
  223. Name: "y1",
  224. Value: FuncAFRF(math.Y1),
  225. },
  226. "yn": &tengo.UserFunction{
  227. Name: "yn",
  228. Value: FuncAIFRF(math.Yn),
  229. },
  230. }