Documentation
¶
Index ¶
- Constants
- func NewForm() *ui.Form
- func ParseNumber(text string) (float64, bool)
- type Engine
- func (e *Engine) Backspace()
- func (e *Engine) Clear()
- func (e *Engine) ClearEntry()
- func (e *Engine) ClearHistory()
- func (e *Engine) Digit(d int)
- func (e *Engine) Display() string
- func (e *Engine) Equals()
- func (e *Engine) Expression() string
- func (e *Engine) HasError() bool
- func (e *Engine) HasMemory() bool
- func (e *Engine) History() []HistoryEntry
- func (e *Engine) MemoryAdd()
- func (e *Engine) MemoryClear()
- func (e *Engine) MemoryRecall()
- func (e *Engine) MemorySubtract()
- func (e *Engine) Negate()
- func (e *Engine) Operator(op rune)
- func (e *Engine) Percent()
- func (e *Engine) Point()
- func (e *Engine) Reciprocal()
- func (e *Engine) SetText(text string) bool
- func (e *Engine) Sqrt()
- func (e *Engine) Square()
- func (e *Engine) Text() string
- type HistoryEntry
Constants ¶
const ( OpAdd = '+' OpSub = '−' OpMul = '×' OpDiv = '÷' )
Operators accepted by Operator.
Variables ¶
This section is empty.
Functions ¶
func NewForm ¶
NewForm is a desktop calculator in the style of the Windows one: a large right-aligned display under the pending expression, a keypad of expanding buttons with the "=" as the accent (primary role), memory keys, full keyboard input (digits, operators, Enter, Backspace, Esc, Delete), Ctrl+C / Ctrl+V through the clipboard, a main menu, and a history Table that is shown with a ToggleSwitch or View > History; a click on a row recalls its result, a right click opens a context menu. The logic is in Engine, a plain Go type with unit tests.
func ParseNumber ¶
ParseNumber parses a number the way people write it: with spaces, thousands separators or a decimal comma.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the calculator logic without any UI: a standard calculator that evaluates left to right (2 + 3 × 4 = 20), repeats the last operation on a repeated "=", and has a memory register and a history of results.
func (*Engine) Clear ¶
func (e *Engine) Clear()
Clear (C) resets the calculation; memory and history are kept.
func (*Engine) ClearEntry ¶
func (e *Engine) ClearEntry()
ClearEntry (CE) clears the current number, keeping the pending operation.
func (*Engine) ClearHistory ¶
func (e *Engine) ClearHistory()
ClearHistory forgets the finished calculations.
func (*Engine) Equals ¶
func (e *Engine) Equals()
Equals evaluates the pending operation; without one it repeats the last.
func (*Engine) Expression ¶
Expression is the pending expression: "12 + 7 =".
func (*Engine) History ¶
func (e *Engine) History() []HistoryEntry
History returns the finished calculations, the oldest first.
func (*Engine) MemoryAdd ¶
func (e *Engine) MemoryAdd()
MemoryAdd (M+) adds the current number to the memory.
func (*Engine) MemoryRecall ¶
func (e *Engine) MemoryRecall()
MemoryRecall (MR) enters the number in the memory.
func (*Engine) MemorySubtract ¶
func (e *Engine) MemorySubtract()
MemorySubtract (M−) subtracts the current number from the memory.
func (*Engine) Negate ¶
func (e *Engine) Negate()
Negate (±) changes the sign of the current number.
func (*Engine) Percent ¶
func (e *Engine) Percent()
Percent: in "a + b %" and "a − b %" b becomes b percent of a, otherwise b / 100.
func (*Engine) Reciprocal ¶
func (e *Engine) Reciprocal()
Reciprocal replaces the current number with 1/x.
func (*Engine) SetText ¶
SetText enters a number given as text (pasted, recalled from the history): "1,234.5", "1 234,5" and "-2e3" are accepted. It reports whether the text was a number.
func (*Engine) Sqrt ¶
func (e *Engine) Sqrt()
Sqrt replaces the current number with its square root.
type HistoryEntry ¶
HistoryEntry is one finished calculation.