var result: nullable Numeric = null
# Last operation pushed with `push_op`, to be executed on the next push
- var last_op: nullable Char = null
+ var last_op: nullable Text = null
# Value currently being entered
var current: nullable FlatBuffer = null
var buf = new FlatBuffer
- if result != null and (current == null or last_op != '=') then
- if last_op == '=' then buf.append "= "
+ if result != null and (current == null or last_op != "=") then
+ if last_op == "=" then buf.append "= "
buf.append result.to_s
buf.add ' '
end
- if last_op != null and last_op != '=' then
- buf.add last_op
+ if last_op != null and last_op != "=" then
+ buf.append last_op
buf.add ' '
end
end
# Push operation `op`, will usually execute the last operation
- fun push_op(op: Char)
+ fun push_op(op: Text)
do
apply_last_op_if_any
- if op == 'C' then
+ if op == "C" then
self.result = null
last_op = null
else
current.add digit.to_s.chars.first
self.current = current
- if last_op == '=' then
+ if last_op == "=" then
self.result = null
last_op = null
end
if op == null then
result = current.to_n
else if result != null then
- if op == '+' then
+ if op == "+" then
result = result.add(current.to_n)
- else if op == '-' then
+ else if op == "-" then
result = result.sub(current.to_n)
- else if op == '/' then
+ else if op == "/" or op == "÷" then
result = result.div(current.to_n)
- else if op == '*' then
+ else if op == "*" or op == "×" then
result = result.mul(current.to_n)
end
end