74 lines
1.8 KiB
GDScript
74 lines
1.8 KiB
GDScript
extends Control
|
|
|
|
@export var Text : LineEdit
|
|
var MathStuff = Math.new()
|
|
|
|
var Operation = ""
|
|
var Number = null
|
|
|
|
func GetKeyInput(new_text: String):
|
|
var Key = new_text.substr(len(new_text) - 1, len(new_text))
|
|
if Key == "+":
|
|
Operation_Change("Add")
|
|
Text.text = ""
|
|
elif Key == "-":
|
|
Operation_Change("Subtract")
|
|
Text.text = ""
|
|
elif Key == "*":
|
|
Operation_Change("Multiply")
|
|
Text.text = ""
|
|
elif Key == "/":
|
|
Operation_Change("Divide")
|
|
Text.text = ""
|
|
elif Key == "=":
|
|
Calculate()
|
|
elif Key == "N":
|
|
Text.text = new_text.substr(0, len(new_text) - 1) + "-"
|
|
elif Key == "C":
|
|
Scrub()
|
|
|
|
func Operation_Change(Operator : String):
|
|
if Operation != "":
|
|
Calculate()
|
|
Operation = Operator
|
|
Number = float(Text.text)
|
|
Text.text = ""
|
|
|
|
func Calculate():
|
|
match(Operation):
|
|
"Add":
|
|
Text.text = "%.10f" % (Number + float(Text.text))
|
|
"Subtract":
|
|
Text.text = "%.10f" % (Number - float(Text.text))
|
|
"Multiply":
|
|
Text.text = "%.10f" % (Number * float(Text.text))
|
|
"Divide":
|
|
Text.text = "%.10f" % (Number / float(Text.text))
|
|
"Root":
|
|
Text.text = "%.10f" % (pow(Number, 1 / float(Text.text)))
|
|
"Pow":
|
|
Text.text = "%.10f" % (pow(Number, float(Text.text)))
|
|
"Log":
|
|
Text.text = "%.10f" % (log(Number) / log(float(Text.text)))
|
|
Operation = ""
|
|
Number = null
|
|
|
|
func Instant_Calculate(FOperation: String):
|
|
match(FOperation):
|
|
"PowEuler":
|
|
Text.text = "%.10f" % (pow(MathStuff.MathConstants.e, float(Text.text)))
|
|
"RootEuler":
|
|
Text.text = "%.10f" % (log(float(Text.text)) / log(MathStuff.MathConstants.e))
|
|
"Factorial":
|
|
Text.text = "%.10f" % (float(MathStuff.Functions.FactorialWhole(int(Text.text))))
|
|
|
|
func AddNumber(thing: int):
|
|
Text.text = Text.text + str(thing)
|
|
|
|
func AddString(thing: String):
|
|
Text.text = Text.text + thing
|
|
|
|
func Scrub():
|
|
Operation = ""
|
|
Text.text = ""
|
|
Number = null
|