forked from candid82/joker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_math.go
78 lines (58 loc) · 1.54 KB
/
a_math.go
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
70
71
72
73
74
75
76
77
78
// This file is generated by generate-std.joke script. Do not edit manually!
package math
import (
. "github.com/candid82/joker/core"
)
var mathNamespace = GLOBAL_ENV.EnsureNamespace(MakeSymbol("joker.math"))
var cos_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 1:
x := ExtractNumber(args, 0)
res := cos(x)
return MakeDouble(res)
default:
PanicArity(c)
}
return NIL
}
var hypot_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 2:
p := ExtractNumber(args, 0)
q := ExtractNumber(args, 1)
res := hypot(p, q)
return MakeDouble(res)
default:
PanicArity(c)
}
return NIL
}
var sin_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 1:
x := ExtractNumber(args, 0)
res := sin(x)
return MakeDouble(res)
default:
PanicArity(c)
}
return NIL
}
func init() {
mathNamespace.ResetMeta(MakeMeta(nil, "Provides basic constants and mathematical functions.", "1.0"))
mathNamespace.InternVar("cos", cos_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("x"))),
`Returns the cosine of the radian argument x.`, "1.0"))
mathNamespace.InternVar("hypot", hypot_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("p"), MakeSymbol("q"))),
`Returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.`, "1.0"))
mathNamespace.InternVar("sin", sin_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("x"))),
`Returns the sine of the radian argument x.`, "1.0"))
}