math.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. "maxFloat32": &tengo.Float{Value: math.MaxFloat32},
  19. "smallestNonzeroFloat32": &tengo.Float{Value: math.SmallestNonzeroFloat32},
  20. "maxFloat64": &tengo.Float{Value: math.MaxFloat64},
  21. "smallestNonzeroFloat64": &tengo.Float{Value: math.SmallestNonzeroFloat64},
  22. "maxInt": &tengo.Int{Value: math.MaxInt},
  23. "minInt": &tengo.Int{Value: math.MinInt},
  24. "maxInt8": &tengo.Int{Value: math.MaxInt8},
  25. "minInt8": &tengo.Int{Value: math.MinInt8},
  26. "maxInt16": &tengo.Int{Value: math.MaxInt16},
  27. "minInt16": &tengo.Int{Value: math.MinInt16},
  28. "maxInt32": &tengo.Int{Value: math.MaxInt32},
  29. "minInt32": &tengo.Int{Value: math.MinInt32},
  30. "maxInt64": &tengo.Int{Value: math.MaxInt64},
  31. "minInt64": &tengo.Int{Value: math.MinInt64},
  32. "abs": &tengo.UserFunction{
  33. Name: "abs",
  34. Value: FuncAFRF(math.Abs),
  35. },
  36. "acos": &tengo.UserFunction{
  37. Name: "acos",
  38. Value: FuncAFRF(math.Acos),
  39. },
  40. "acosh": &tengo.UserFunction{
  41. Name: "acosh",
  42. Value: FuncAFRF(math.Acosh),
  43. },
  44. "asin": &tengo.UserFunction{
  45. Name: "asin",
  46. Value: FuncAFRF(math.Asin),
  47. },
  48. "asinh": &tengo.UserFunction{
  49. Name: "asinh",
  50. Value: FuncAFRF(math.Asinh),
  51. },
  52. "atan": &tengo.UserFunction{
  53. Name: "atan",
  54. Value: FuncAFRF(math.Atan),
  55. },
  56. "atan2": &tengo.UserFunction{
  57. Name: "atan2",
  58. Value: FuncAFFRF(math.Atan2),
  59. },
  60. "atanh": &tengo.UserFunction{
  61. Name: "atanh",
  62. Value: FuncAFRF(math.Atanh),
  63. },
  64. "cbrt": &tengo.UserFunction{
  65. Name: "cbrt",
  66. Value: FuncAFRF(math.Cbrt),
  67. },
  68. "ceil": &tengo.UserFunction{
  69. Name: "ceil",
  70. Value: FuncAFRF(math.Ceil),
  71. },
  72. "copysign": &tengo.UserFunction{
  73. Name: "copysign",
  74. Value: FuncAFFRF(math.Copysign),
  75. },
  76. "cos": &tengo.UserFunction{
  77. Name: "cos",
  78. Value: FuncAFRF(math.Cos),
  79. },
  80. "cosh": &tengo.UserFunction{
  81. Name: "cosh",
  82. Value: FuncAFRF(math.Cosh),
  83. },
  84. "dim": &tengo.UserFunction{
  85. Name: "dim",
  86. Value: FuncAFFRF(math.Dim),
  87. },
  88. "erf": &tengo.UserFunction{
  89. Name: "erf",
  90. Value: FuncAFRF(math.Erf),
  91. },
  92. "erfc": &tengo.UserFunction{
  93. Name: "erfc",
  94. Value: FuncAFRF(math.Erfc),
  95. },
  96. "exp": &tengo.UserFunction{
  97. Name: "exp",
  98. Value: FuncAFRF(math.Exp),
  99. },
  100. "exp2": &tengo.UserFunction{
  101. Name: "exp2",
  102. Value: FuncAFRF(math.Exp2),
  103. },
  104. "expm1": &tengo.UserFunction{
  105. Name: "expm1",
  106. Value: FuncAFRF(math.Expm1),
  107. },
  108. "floor": &tengo.UserFunction{
  109. Name: "floor",
  110. Value: FuncAFRF(math.Floor),
  111. },
  112. "gamma": &tengo.UserFunction{
  113. Name: "gamma",
  114. Value: FuncAFRF(math.Gamma),
  115. },
  116. "hypot": &tengo.UserFunction{
  117. Name: "hypot",
  118. Value: FuncAFFRF(math.Hypot),
  119. },
  120. "ilogb": &tengo.UserFunction{
  121. Name: "ilogb",
  122. Value: FuncAFRI(math.Ilogb),
  123. },
  124. "inf": &tengo.UserFunction{
  125. Name: "inf",
  126. Value: FuncAIRF(math.Inf),
  127. },
  128. "is_inf": &tengo.UserFunction{
  129. Name: "is_inf",
  130. Value: FuncAFIRB(math.IsInf),
  131. },
  132. "is_nan": &tengo.UserFunction{
  133. Name: "is_nan",
  134. Value: FuncAFRB(math.IsNaN),
  135. },
  136. "j0": &tengo.UserFunction{
  137. Name: "j0",
  138. Value: FuncAFRF(math.J0),
  139. },
  140. "j1": &tengo.UserFunction{
  141. Name: "j1",
  142. Value: FuncAFRF(math.J1),
  143. },
  144. "jn": &tengo.UserFunction{
  145. Name: "jn",
  146. Value: FuncAIFRF(math.Jn),
  147. },
  148. "ldexp": &tengo.UserFunction{
  149. Name: "ldexp",
  150. Value: FuncAFIRF(math.Ldexp),
  151. },
  152. "log": &tengo.UserFunction{
  153. Name: "log",
  154. Value: FuncAFRF(math.Log),
  155. },
  156. "log10": &tengo.UserFunction{
  157. Name: "log10",
  158. Value: FuncAFRF(math.Log10),
  159. },
  160. "log1p": &tengo.UserFunction{
  161. Name: "log1p",
  162. Value: FuncAFRF(math.Log1p),
  163. },
  164. "log2": &tengo.UserFunction{
  165. Name: "log2",
  166. Value: FuncAFRF(math.Log2),
  167. },
  168. "logb": &tengo.UserFunction{
  169. Name: "logb",
  170. Value: FuncAFRF(math.Logb),
  171. },
  172. "max": &tengo.UserFunction{
  173. Name: "max",
  174. Value: FuncAFFRF(math.Max),
  175. },
  176. "min": &tengo.UserFunction{
  177. Name: "min",
  178. Value: FuncAFFRF(math.Min),
  179. },
  180. "mod": &tengo.UserFunction{
  181. Name: "mod",
  182. Value: FuncAFFRF(math.Mod),
  183. },
  184. "nan": &tengo.UserFunction{
  185. Name: "nan",
  186. Value: FuncARF(math.NaN),
  187. },
  188. "nextafter": &tengo.UserFunction{
  189. Name: "nextafter",
  190. Value: FuncAFFRF(math.Nextafter),
  191. },
  192. "pow": &tengo.UserFunction{
  193. Name: "pow",
  194. Value: FuncAFFRF(math.Pow),
  195. },
  196. "pow10": &tengo.UserFunction{
  197. Name: "pow10",
  198. Value: FuncAIRF(math.Pow10),
  199. },
  200. "remainder": &tengo.UserFunction{
  201. Name: "remainder",
  202. Value: FuncAFFRF(math.Remainder),
  203. },
  204. "signbit": &tengo.UserFunction{
  205. Name: "signbit",
  206. Value: FuncAFRB(math.Signbit),
  207. },
  208. "sin": &tengo.UserFunction{
  209. Name: "sin",
  210. Value: FuncAFRF(math.Sin),
  211. },
  212. "sinh": &tengo.UserFunction{
  213. Name: "sinh",
  214. Value: FuncAFRF(math.Sinh),
  215. },
  216. "sqrt": &tengo.UserFunction{
  217. Name: "sqrt",
  218. Value: FuncAFRF(math.Sqrt),
  219. },
  220. "tan": &tengo.UserFunction{
  221. Name: "tan",
  222. Value: FuncAFRF(math.Tan),
  223. },
  224. "tanh": &tengo.UserFunction{
  225. Name: "tanh",
  226. Value: FuncAFRF(math.Tanh),
  227. },
  228. "trunc": &tengo.UserFunction{
  229. Name: "trunc",
  230. Value: FuncAFRF(math.Trunc),
  231. },
  232. "y0": &tengo.UserFunction{
  233. Name: "y0",
  234. Value: FuncAFRF(math.Y0),
  235. },
  236. "y1": &tengo.UserFunction{
  237. Name: "y1",
  238. Value: FuncAFRF(math.Y1),
  239. },
  240. "yn": &tengo.UserFunction{
  241. Name: "yn",
  242. Value: FuncAIFRF(math.Yn),
  243. },
  244. }