math: Add trigonometric functions and some angle helper functions

This commit adds these new template functions in the `math` namespace:

math.Acos
math.Asin
math.Atan
math.Atan2
math.Cos
math.Pi
math.Sin
math.Tan
math.ToDegrees
math.ToRadians

Co-authored-by: Joe Mooring <joe@mooring.com>
This commit is contained in:
raoulb
2024-07-29 11:05:36 +02:00
committed by GitHub
parent 0e00561620
commit 9d2b5f98d0
14 changed files with 933 additions and 54 deletions

View File

@@ -38,6 +38,13 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Acos,
nil,
[][2]string{
{"{{ math.Acos 1 }}", "0"},
},
)
ns.AddMethodMapping(ctx.Add,
[]string{"add"},
[][2]string{
@@ -45,6 +52,27 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Asin,
nil,
[][2]string{
{"{{ math.Asin 1 }}", "1.5707963267948966"},
},
)
ns.AddMethodMapping(ctx.Atan,
nil,
[][2]string{
{"{{ math.Atan 1 }}", "0.7853981633974483"},
},
)
ns.AddMethodMapping(ctx.Atan2,
nil,
[][2]string{
{"{{ math.Atan2 1 2 }}", "0.4636476090008061"},
},
)
ns.AddMethodMapping(ctx.Ceil,
nil,
[][2]string{
@@ -52,6 +80,13 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Cos,
nil,
[][2]string{
{"{{ math.Cos 1 }}", "0.5403023058681398"},
},
)
ns.AddMethodMapping(ctx.Div,
[]string{"div"},
[][2]string{
@@ -108,6 +143,13 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Pi,
nil,
[][2]string{
{"{{ math.Pi }}", "3.141592653589793"},
},
)
ns.AddMethodMapping(ctx.Pow,
[]string{"pow"},
[][2]string{
@@ -129,6 +171,13 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Sin,
nil,
[][2]string{
{"{{ math.Sin 1 }}", "0.8414709848078965"},
},
)
ns.AddMethodMapping(ctx.Sqrt,
nil,
[][2]string{
@@ -143,6 +192,27 @@ func init() {
},
)
ns.AddMethodMapping(ctx.Tan,
nil,
[][2]string{
{"{{ math.Tan 1 }}", "1.557407724654902"},
},
)
ns.AddMethodMapping(ctx.ToDegrees,
nil,
[][2]string{
{"{{ math.ToDegrees 1.5707963267948966 }}", "90"},
},
)
ns.AddMethodMapping(ctx.ToRadians,
nil,
[][2]string{
{"{{ math.ToRadians 90 }}", "1.5707963267948966"},
},
)
return ns
}