mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
trig
This commit is contained in:
59
src/trig.go
Normal file
59
src/trig.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
var PIFloatInaccuracy number = newNumber()
|
||||
|
||||
func init() {
|
||||
PIFloatInaccuracy.SetFloat64(math.Asin(1) * 2)
|
||||
}
|
||||
|
||||
var ArSin = builtinFunc{"sin", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{TYPE: "Runtime Error",
|
||||
message: fmt.Sprintf("sin expected 1 argument, got %d", len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return nil, ArErr{TYPE: "Runtime Error",
|
||||
message: fmt.Sprintf("sin 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.Sin(n))
|
||||
return outputnum, ArErr{}
|
||||
}}
|
||||
var ArArcsin = builtinFunc{"arcsin", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{TYPE: "Runtime Error",
|
||||
message: fmt.Sprintf("arcsin expected 1 argument, got %d", len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return nil, ArErr{TYPE: "Runtime Error",
|
||||
message: fmt.Sprintf("arcsin 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("arcsin expected number between -1 and 1, got %s", anyToArgon(n, true, true, 3, 0, false, 0)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
outputnum := newNumber().SetFloat64(math.Asin(n))
|
||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||
outputnum.Mul(outputnum, PI)
|
||||
return outputnum, ArErr{}
|
||||
}}
|
||||
Reference in New Issue
Block a user