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:
@@ -79,6 +79,7 @@ func makeGlobal() ArObject {
|
||||
vars.obj["log"] = builtinFunc{"log", ArgonLog}
|
||||
vars.obj["logN"] = builtinFunc{"logN", ArgonLogN}
|
||||
vars.obj["thread"] = builtinFunc{"thread", ArThread}
|
||||
vars.obj["input"] = ArInput
|
||||
vars.obj["round"] = builtinFunc{"round", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return nil, ArErr{TYPE: "round", message: "round takes 1 argument",
|
||||
@@ -132,6 +133,18 @@ func makeGlobal() ArObject {
|
||||
vars.obj["json"] = ArJSON
|
||||
vars.obj["sin"] = ArSin
|
||||
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) {
|
||||
fmt.Println(a)
|
||||
if len(a) == 0 {
|
||||
|
||||
@@ -56,5 +56,6 @@ func getPassword(args ...any) (string, error) {
|
||||
fmt.Print("*")
|
||||
}
|
||||
}
|
||||
fmt.Print("\r")
|
||||
return string(password), nil
|
||||
}
|
||||
|
||||
@@ -120,18 +120,19 @@ var ArTerm = Map(anymap{
|
||||
fmt.Printf("\x1b[%dm%s\x1b[0m", 34, fmt.Sprint(anyToArgon(id, false, true, 3, 0, false, 0), ": ", timesince)+"\n")
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"input": Map(
|
||||
anymap{
|
||||
"password": builtinFunc{"password", func(args ...any) (any, ArErr) {
|
||||
resp, err := getPassword(args...)
|
||||
if err != nil {
|
||||
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return ArString(resp), ArErr{}
|
||||
}},
|
||||
"__call__": builtinFunc{"input", func(args ...any) (any, ArErr) {
|
||||
return input(args...), ArErr{}
|
||||
}},
|
||||
},
|
||||
),
|
||||
})
|
||||
|
||||
var ArInput = Map(
|
||||
anymap{
|
||||
"password": builtinFunc{"password", func(args ...any) (any, ArErr) {
|
||||
resp, err := getPassword(args...)
|
||||
if err != nil {
|
||||
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return ArString(resp), ArErr{}
|
||||
}},
|
||||
"__call__": builtinFunc{"input", func(args ...any) (any, 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)
|
||||
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