mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
add other trig funcs
This commit is contained in:
@@ -82,6 +82,7 @@ func makeGlobal(allowDocument bool) ArObject {
|
|||||||
vars.obj["log"] = builtinFunc{"log", ArgonLog}
|
vars.obj["log"] = builtinFunc{"log", ArgonLog}
|
||||||
vars.obj["logN"] = builtinFunc{"logN", ArgonLogN}
|
vars.obj["logN"] = builtinFunc{"logN", ArgonLogN}
|
||||||
vars.obj["thread"] = builtinFunc{"thread", ArThread}
|
vars.obj["thread"] = builtinFunc{"thread", ArThread}
|
||||||
|
vars.obj["input"] = ArInput
|
||||||
vars.obj["round"] = builtinFunc{"round", func(a ...any) (any, ArErr) {
|
vars.obj["round"] = builtinFunc{"round", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return nil, ArErr{TYPE: "round", message: "round takes 1 argument",
|
return nil, ArErr{TYPE: "round", message: "round takes 1 argument",
|
||||||
@@ -135,6 +136,18 @@ func makeGlobal(allowDocument bool) ArObject {
|
|||||||
vars.obj["json"] = ArJSON
|
vars.obj["json"] = ArJSON
|
||||||
vars.obj["sin"] = ArSin
|
vars.obj["sin"] = ArSin
|
||||||
vars.obj["arcsin"] = ArArcsin
|
vars.obj["arcsin"] = ArArcsin
|
||||||
|
vars.obj["cos"] = ArCos
|
||||||
|
vars.obj["arccos"] = ArArccos
|
||||||
|
vars.obj["tan"] = ArTan
|
||||||
|
vars.obj["arctan"] = ArArctan
|
||||||
|
vars.obj["cosec"] = ArCosec
|
||||||
|
vars.obj["arccosec"] = ArArccosec
|
||||||
|
vars.obj["sec"] = ArSec
|
||||||
|
vars.obj["arcsec"] = ArArcsec
|
||||||
|
vars.obj["cot"] = ArCot
|
||||||
|
vars.obj["arccot"] = ArArccot
|
||||||
|
vars.obj["todeg"] = ArToDeg
|
||||||
|
vars.obj["torad"] = ArToRad
|
||||||
vars.obj["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
vars.obj["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
||||||
fmt.Println(a)
|
fmt.Println(a)
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
|
|||||||
@@ -56,5 +56,6 @@ func getPassword(args ...any) (string, error) {
|
|||||||
fmt.Print("*")
|
fmt.Print("*")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Print("\r")
|
||||||
return string(password), nil
|
return string(password), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ var ArTerm = Map(anymap{
|
|||||||
fmt.Printf("\x1b[%dm%s\x1b[0m", 34, fmt.Sprint(anyToArgon(id, false, true, 3, 0, false, 0), ": ", timesince)+"\n")
|
fmt.Printf("\x1b[%dm%s\x1b[0m", 34, fmt.Sprint(anyToArgon(id, false, true, 3, 0, false, 0), ": ", timesince)+"\n")
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}},
|
}},
|
||||||
"input": Map(
|
})
|
||||||
|
|
||||||
|
var ArInput = Map(
|
||||||
anymap{
|
anymap{
|
||||||
"password": builtinFunc{"password", func(args ...any) (any, ArErr) {
|
"password": builtinFunc{"password", func(args ...any) (any, ArErr) {
|
||||||
resp, err := getPassword(args...)
|
resp, err := getPassword(args...)
|
||||||
@@ -133,5 +135,4 @@ var ArTerm = Map(anymap{
|
|||||||
return input(args...), ArErr{}
|
return input(args...), ArErr{}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
})
|
|
||||||
|
|||||||
263
src/trig.go
263
src/trig.go
@@ -57,3 +57,266 @@ var ArArcsin = builtinFunc{"arcsin", func(args ...any) (any, ArErr) {
|
|||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
var ArCos = builtinFunc{"cos", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("cos expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("cos expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, PI)
|
||||||
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(math.Cos(n))
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
var ArArccos = builtinFunc{"arccos", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccos expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccos expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := args[0].(number)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
if n < -1 || n > 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccos expected number between -1 and 1, got %s", anyToArgon(n, true, true, 3, 0, false, 0)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputnum := newNumber().SetFloat64(math.Acos(n))
|
||||||
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
|
outputnum.Mul(outputnum, PI)
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArTan = builtinFunc{"tan", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("tan expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("tan expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, PI)
|
||||||
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(math.Tan(n))
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
var ArArctan = builtinFunc{"arctan", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arctan expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arctan expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := args[0].(number)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(math.Atan(n))
|
||||||
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
|
outputnum.Mul(outputnum, PI)
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArCosec = builtinFunc{"cosec", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("cosec expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("cosec expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, PI)
|
||||||
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(1 / math.Sin(n))
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
var ArArccosec = builtinFunc{"arccosec", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccosec expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccosec expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := args[0].(number)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
if n < -1 || n > 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccosec expected number between -1 and 1, got %s", anyToArgon(n, true, true, 3, 0, false, 0)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputnum := newNumber().SetFloat64(math.Asin(1 / n))
|
||||||
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
|
outputnum.Mul(outputnum, PI)
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArSec = builtinFunc{"sec", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("sec expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("sec expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, PI)
|
||||||
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(1 / math.Cos(n))
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArArcsec = builtinFunc{"arcsec", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arcsec expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arcsec expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := args[0].(number)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
if n < -1 || n > 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arcsec expected number between -1 and 1, got %s", anyToArgon(n, true, true, 3, 0, false, 0)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputnum := newNumber().SetFloat64(math.Acos(1 / n))
|
||||||
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
|
outputnum.Mul(outputnum, PI)
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArCot = builtinFunc{"cot", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("cot expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("cot expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, PI)
|
||||||
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(1 / math.Tan(n))
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArArccot = builtinFunc{"arccot", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccot expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("arccot expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := args[0].(number)
|
||||||
|
n, _ := num.Float64()
|
||||||
|
outputnum := newNumber().SetFloat64(math.Atan(1 / n))
|
||||||
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
|
outputnum.Mul(outputnum, PI)
|
||||||
|
return outputnum, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArToDeg = builtinFunc{"toDeg", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("toDeg expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("toDeg expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, PI)
|
||||||
|
num.Mul(num, newNumber().SetInt64(180))
|
||||||
|
return num, ArErr{}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var ArToRad = builtinFunc{"toRad", func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("toRad expected 1 argument, got %d", len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error",
|
||||||
|
message: fmt.Sprintf("toRad expected number, got %s", typeof(args[0])),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := newNumber().Set(args[0].(number))
|
||||||
|
num.Quo(num, newNumber().SetInt64(180))
|
||||||
|
num.Mul(num, PI)
|
||||||
|
return num, ArErr{}
|
||||||
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user