clac

package module
v0.0.0-...-ceb2fae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2017 License: MIT Imports: 4 Imported by: 1

README

clac

Clac is a practical RPN calculator for the terminal and shell.

Features include:

  • Command line history
  • Unlimited undo/redo
  • Integer input using C-style decimal, octal, or hexidecimal syntax
  • Decimal and hexidecimal display of all stack values, all the time
  • Pipeline mode processes input from stdin and prints results to stdout

Clac uses Rob Pike's Ivy calculator for exact/high precision calculations. Ivy requires Go 1.5, hence so does Clac.

To get it, make sure you have Go installed, then run: go get github.com/ianremmler/clac/cmd/clac.

Documentation

Overview

Package clac implements an RPN calculator.

Index

Constants

This section is empty.

Variables

View Source
var (
	E, Pi, Phi value.Value

	ErrTooFewArgs    = errors.New("too few arguments")
	ErrInvalidArg    = errors.New("invalid argument")
	ErrNoMoreChanges = errors.New("no more changes")
	ErrNoHistUpdate  = errors.New("") // for cmds that don't add to history

)

Functions

func ParseNum

func ParseNum(tok string) (val value.Value, err error)

ParseNum wraps value.Parse() to handle panics on unexpected input

func SetFormat

func SetFormat(format string)

SetFormat sets the ivy output format

func Sprint

func Sprint(val value.Value) string

Sprint returns a stringified value

func Trunc

func Trunc(val value.Value) (value.Value, error)

Trunc returns the given value rounded to the nearest integer toward 0

Types

type Clac

type Clac struct {
	// contains filtered or unexported fields
}

Clac represents an RPN calculator.

func New

func New() *Clac

New returns an initialized Clac instance.

func (*Clac) Abs

func (c *Clac) Abs() error

Abs returns the absolute value of x.

func (*Clac) Acos

func (c *Clac) Acos() error

Acos returns the arccosine of x.

func (*Clac) Add

func (c *Clac) Add() error

Add returns the sum of y and x.

func (*Clac) And

func (c *Clac) And() error

And returns the bitwise and of the integer portions of y and x.

func (*Clac) AndN

func (c *Clac) AndN() error

AndN returns the bitwise and of the integer portions of the last x stack values.

func (*Clac) Asin

func (c *Clac) Asin() error

Asin returns the arcsine of x.

func (*Clac) Atan

func (c *Clac) Atan() error

Atan returns the arctangent of x.

func (*Clac) Atan2

func (c *Clac) Atan2() error

Atan2 returns the arctangent of y / x

func (*Clac) Avg

func (c *Clac) Avg() error

Avg returns the mean of the last x stack values

func (*Clac) Ceil

func (c *Clac) Ceil() error

Ceil returns smallest integer not less than x.

func (*Clac) Clear

func (c *Clac) Clear() error

Clear clears the stack.

func (*Clac) Comb

func (c *Clac) Comb() error

Comb returns the number of combinations of x taken from y

func (*Clac) Cos

func (c *Clac) Cos() error

Cos returns the cosine of x.

func (*Clac) Cross

func (c *Clac) Cross() error

Cross returns the cross product of two 3D vectors The vectors are composed of the last 6 items on the stack

func (*Clac) DegToRad

func (c *Clac) DegToRad() error

DegToRad converts a value in degrees to radians.

func (*Clac) Depth

func (c *Clac) Depth() error

Depth returns the number of stack values

func (*Clac) Div

func (c *Clac) Div() error

Div returns the quotient of y divided by x.

func (*Clac) Dot

func (c *Clac) Dot() error

Dot returns the dot product of two vectors of size x The vectors are composed of the 2*x items on the stack above x

func (*Clac) Dot3

func (c *Clac) Dot3() error

Dot3 returns the dot product of two 3D vectors The vectors are composed of the last 6 items on the stack

func (*Clac) Drop

func (c *Clac) Drop() error

Drop drops the last stack value.

func (*Clac) DropN

func (c *Clac) DropN() error

DropN drops the last x stack values.

func (*Clac) DropR

func (c *Clac) DropR() error

DropR drops a range of x stack values, starting at index y.

func (*Clac) Dup

func (c *Clac) Dup() error

Dup duplicates the last stack value.

func (*Clac) DupN

func (c *Clac) DupN() error

DupN duplicates the last x stack values.

func (*Clac) DupR

func (c *Clac) DupR() error

DupR duplicates a range of x stack values, starting at index y.

func (*Clac) EnableHistory

func (c *Clac) EnableHistory(enable bool)

EnableHistory sets whether to retain history

func (*Clac) Exec

func (c *Clac) Exec(f func() error) error

Exec executes a clac command, along with necessary bookkeeping

func (*Clac) Exp

func (c *Clac) Exp() error

Exp returns e to the power of x.

func (*Clac) Factorial

func (c *Clac) Factorial() error

Factorial returns the factorial of x

func (*Clac) Floor

func (c *Clac) Floor() error

Floor returns largest integer not greater than x.

func (*Clac) Hypot

func (c *Clac) Hypot() error

Hypot calculates the 2D hypotenuse of a right triangles with legs x and y

func (*Clac) IntDiv

func (c *Clac) IntDiv() error

IntDiv returns the quotient of y divided by x.

func (*Clac) Inv

func (c *Clac) Inv() error

Inv returns the inverse of x.

func (*Clac) Lg

func (c *Clac) Lg() error

Lg returns the base 2 logarithm of x.

func (*Clac) Ln

func (c *Clac) Ln() error

Ln returns the natural log of x.

func (*Clac) Log

func (c *Clac) Log() error

Log returns the base 10 logarithm of x.

func (*Clac) LogN

func (c *Clac) LogN() error

LogN returns the base x log of y.

func (*Clac) Mag

func (c *Clac) Mag() error

Mag returns the magnitude of the vector represented by the last x stack values

func (*Clac) Max

func (c *Clac) Max() error

Max returns the maximum of x and y

func (*Clac) MaxN

func (c *Clac) MaxN() error

MaxN returns the maximum of the last x stack values.

func (*Clac) Min

func (c *Clac) Min() error

Min returns the minimum of x and y

func (*Clac) MinN

func (c *Clac) MinN() error

MinN returns the minimum of the last x stack values.

func (*Clac) Mod

func (c *Clac) Mod() error

Mod returns the remainder of y divided by x.

func (*Clac) Mul

func (c *Clac) Mul() error

Mul returns the product of y and x.

func (*Clac) Neg

func (c *Clac) Neg() error

Neg returns the negation of x.

func (*Clac) Not

func (c *Clac) Not() error

Not returns the bitwise not of the integer portion x.

func (*Clac) Or

func (c *Clac) Or() error

Or returns the bitwise or of the integer portions of y and x.

func (*Clac) OrN

func (c *Clac) OrN() error

OrN returns the bitwise or of the integer portions of the last x stack values.

func (*Clac) Perm

func (c *Clac) Perm() error

Perm returns the number of permutations of x taken from y

func (*Clac) Pick

func (c *Clac) Pick() error

Pick duplicates the stack value at index x.

func (*Clac) PolarToRect

func (c *Clac) PolarToRect() error

PolarToRect converts 2D polar coordinates y<x to rectangular coordinates.

func (*Clac) Pop

func (c *Clac) Pop() (value.Value, error)

Pop pops a value off the stack.

func (*Clac) Pow

func (c *Clac) Pow() error

Pow returns y to the x power.

func (*Clac) Pow10

func (c *Clac) Pow10() error

Pow10 returns 10 to the power of x.

func (*Clac) Pow2

func (c *Clac) Pow2() error

Pow2 returns 2 to the power of x.

func (*Clac) Push

func (c *Clac) Push(x value.Value) error

Push pushes a value on the stack.

func (*Clac) RadToDeg

func (c *Clac) RadToDeg() error

RadToDeg converts a value in radians to degrees.

func (*Clac) RectToPolar

func (c *Clac) RectToPolar() error

RectToPolar converts 2D rectangular coordinates y,x to polar coordinates.

func (*Clac) Redo

func (c *Clac) Redo() error

Redo redoes the last undone operation.

func (*Clac) Reset

func (c *Clac) Reset() error

Reset resets clac to its initial state

func (*Clac) Rot

func (c *Clac) Rot() error

Rot rotates the stack value at index x down.

func (*Clac) RotR

func (c *Clac) RotR() error

RotR rotates a range of x stack values, starting at index y, down.

func (*Clac) Sin

func (c *Clac) Sin() error

Sin returns the sine of x.

func (*Clac) Sqrt

func (c *Clac) Sqrt() error

Sqrt returns the square root of x.

func (*Clac) Stack

func (c *Clac) Stack() Stack

Stack returns the current stack.

func (*Clac) Sub

func (c *Clac) Sub() error

Sub returns the difference of y and x.

func (*Clac) Sum

func (c *Clac) Sum() error

Sum returns the sum of the last x stack values

func (*Clac) Swap

func (c *Clac) Swap() error

Swap swaps the last two stack values.

func (*Clac) Tan

func (c *Clac) Tan() error

Tan returns the tangent of x.

func (*Clac) Trunc

func (c *Clac) Trunc() error

Trunc returns x truncated to the nearest integer toward 0.

func (*Clac) Undo

func (c *Clac) Undo() error

Undo undoes the last operation.

func (*Clac) Unrot

func (c *Clac) Unrot() error

Unrot rotates the stack value at index x up.

func (*Clac) UnrotR

func (c *Clac) UnrotR() error

UnrotR rotates a range of x stack values, starting at index y, up.

func (*Clac) Xor

func (c *Clac) Xor() error

Xor returns the bitwise exclusive or of the integer portions of y and x.

func (*Clac) XorN

func (c *Clac) XorN() error

XorN returns the bitwise exclusive or of the integer portions of the last x stack values.

type Stack

type Stack []value.Value

Stack represents a stack of floating point numbers.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL