# MiscEl: Calculator

 Back to MiscEl main page Write a message to author A calculator with many functions and the ability to draw curves and make tables.

### General use

Write a expression and press enter, the result will be displayed in the result field, and copied to the "Last result" page. It is also possible to to write a statement or more statements with ; between, but a valid result will only be shown when the last item on the line is a expression.
A valid expression could be:
`3*4`
or
`sin(pi/17)*power(3,2.3)/(1+cosh(4))`
To store a result for later use:
`var a;`
`a:=3*4`
Or create a permanent variable with: `a`, then right click and select "Create variable", this variable is stored and will last until deleted (starting/stopping the MiscEl program will not delete the variable or the value)
Right click for more options:
• Result to clipboard, copy the result to the clipboard for use elsewhere
• Add to statements, copy the line to the "Statements page"
• Create variable, create a permanent variable, as described above
• Create function, create a permanent function, see description under "Functions" page
Use cursor up/down keys to recall the last expressions entered (From the "Last results" list).

## Pages in calculator

### Last results

A list of the last valid lines for the calculator and the corresponding result. Double click a line to get it back onto the editing line. Right click for more options:
• Result to clipboard, copy the result to the clipboard for use elsewhere
• Add to statements, copy the line to the "Statements page"
• Delete, remove the line

### Statements

List of statements, these are evaluated every time you press enter on the edit line, by using variables it is possible to calculate the same expression/statements many times with different values. Double click to copy the statement to the editing line
Right click for more options:
• Move up/down, change the execute sequence of the statements
• Result to clipboard, copy the result to the clipboard for use elsewhere
• Delete entry, remove the line
• Save, save the statements to a file

### Variables

List of permanent variables, if a local variable with the same name is defined only the local variable will be changed with statements (To get rid of a local variable use `free("name")`).
Global variables can be used anywhere in MiscEl, but the pages will NOT update automatic when a variable is changed (Add or delete a space in a input field to update)! Right click for more options:
• Result to clipboard, copy the contens of the variable to the clipboard for use elsewhere
• Set value, assign the last result from the editing line to the variable
• Del var, remove the global variable

### Functions

List of user defined functions. To define a function write `functionname=expression` in the editing line, then right click and select "Create function". All parameters passed to the function can be accessed in the "param" array, first parameter as index 0.
An example (Two resistor in parallel):
`par=1./(1./param+1./param)`
Use the function by writing:
`par(10k,30k)`
The function can contain more than one statement, use `;` as a delimeter. It is also possible to define variables with the `var` statement, these variables are local, and not saved between invocations of the function.
CAVEAT Any user defined function will not automatic convert to floating point when dividing integers, i.e. 5/2 will always be 2 in a user defined function! A typecast MUST be used (see above example for one way to handle the problem).
Functions can be used anywhere in MiscEl.
Double click to copy the function to the editing line
Right click for more options:
• Result to clipboard, copy the result to the clipboard for use elsewhere
• Add, define current editing line as a function
• Del, remove the selected function

### Const

A list of many different physical (and other) constants. Many of these constants can be directly used in expression anywhere in MiscEl. Use Category to select between different groups of constants. The rows displayet are:
• Name of the constant
• Symbol or name that can be used in MiscEl
• Value of the constant, this value is displayed according to the selected numerical display format
• Unit
Double click to copy the constant to the editing line
Right click for more options:
• Use, same as a doubleclick, copy the constant to the editing line
• Use value, copy the numerical value of the constant to the editing line
• To clipboard, copy the numerical value of the constant to clipboard

### Curve / Table setup

Define formulas for drawing a curve or making a table.
Fields:
 X The x-axis definition, usual just a t Y1 The first curve/column, write a expression with t as independ variable Y2 The second curve/column, write a expression with t as independ variable Start Starting value for t End Final value for t Steps Number of steps between starting and ending value, the X/Y1/Y2 are calculated once for each step Log steps Use logarithmic steps Auto scale Automatic scale the graph to contain the curve Use same scale Y1 and Y2 is displayed with the same scale Left/Right Min/Max X value displayed Bottom/Top Min/Max Y value displayed Log x/y scale Use logarithmic scales Draw Make a curve Fill Make a table

### Help

Shortform help for the calculator

### Curve

Curve generated from "Curve / Table setup"
Right click for more options:
• Curve to clipboard, copy the curve picture to the clipboard for use elsewhere

### Table

Table generated from "Curve / Table setup"
Right click for more options:
• Table to clipboard, copy the table data to the clipboard for use elsewhere, a TAB delimetered format is used
• Table to clipboard XY, copy the X and Y from the table to the clipboard for use elsewhere, a TAB delimetered format is used
• Table to clipboard Y, copy the Y data from the table to the clipboard for use elsewhere, a TAB delimetered format is used

## Specifications

### Numbers

Numbers can be entered in a varity of ways:
• Just the number, as in 123
• Binary, as in 1001B or 1001b
• Octal, as in 177O or 177o
• Hex, as in 1f5H or 1f5h or 0X1f5 or 0x1f5 or \$1f5, all values must start with a digit in the 0..9 range, ffh is not valid, use 0ffh
• Decimal, as in 12.34. Only . (point) is accepted as decimal point, a , (comma) is used as a parameter delimeter and can not be used as decimal point
• Exponent as in 12.34e3 or 12.34E3 or 12e3 or 12E3 (When E is used without a number after, it is a SI prefix and multiplies with 1E18)
• With appended SI prefix as in 12.34k or 12.34M, accepted prefix are YZEPTGMKkcmu�npfazy
• With SI prefix as point, as in 12k34 or 12u34, accepted prefix are YZPTGMKkcmu�npfazy (i.e. E is missing)
• With binary SI prefix, as in 12ki=1024, accepted prefix are YZEPTGMKk
u is used as a easy typeable alternative to �, k is accepted as both lower and upper case, all other prefixes must be in correct case

### Operators

 () Brackets * Multiplication / Division % Returns the remainder of a division, only supported for integers + Addition - Subtraction BitOr Bitwise OR function, only supported for integers BitAnd Bitwise AND function, only supported for integers BitXOR Bitwise XOR function, only supported for integers = or == Equal, result is False=0, True=1 <> Not equal, result is False=0, True=1 < Less, result is False=0, True=1 <= Less equal, result is False=0, True=1 > Greater, result is False=0, True=1 >= Greater equal, result is False=0, True=1 | or OR Logical or (0=False, all other values=True), only supported for integers, result is False=0, True=1 & or AND Logical and (0=False, all other values=True), only supported for integers, result is False=0, True=1 integer?expression1:expression2 Returns expression1 if integer is non-zero else result is expression2

### Statements

 expression Any expression can be used as a statement variable:=expression Assignment to a variable is a statement (variables must be created before use) var name; Create a local variable named "name", this variable will not be shown on the "Variables" page and not saved, defining a variable multiple times is valid and will not change the value of the variable if (expression) statements else statements endif A if statement with or without the else part
This list is not complete

### Datatypes

Automatic type conversion will hide the actuel datatype in many cases, but it is possible to force type conversion with typename(value) i.e. integer(pi) will return a integer (with the value 3). Be carefull with division: 5/2 is either 2 or 2.5 depending on datatype and automatic conversion to real setting (Watch out in user defined functions), (5./2 or (real(5)/2 is always 2.5).
Use VarType(Variable) to check the type of a variable.
 Integer Numbers without a decimalpoint i.e. 1 2 3 4 etc. Real Numbers with the posibility for a decimalpoint i.e. 1.7 3.14 etc. (these numbers can also be without digits after the decimal point) Complex Two real numbers, saved as r and i, only some operations are supported on complex numbers String Any sequence of characters, most mathematical operations are not supported on this type Array A list of datatypes, accessed with [index], the first element is always 0
This list is not complete

### Functions

Sin/Cos/Tan/ArcSin/ArcCos/ArcTanStandard trigonometric functions
todB/todBpwr/fromdB/fromdBpwrConvert to and from dB
ArcTan2(y,x)ArcTan(y/x) angle is in the correct quadrant
CoTan(x)Same as 1/tan(x)
Hypot(x,y)Same as sqrt(sqr(x)+sqr(y))
sinh/cosh/tanh/ArcSinh/ArcCosh/arcTanhHyperbolic trigonometric functions
Ln/Log10/Log2Logarithm functions Natural/base 10/base 2
LogN(Base,x)Logarithm with any base
Power(value,exponent)Raises value to exponent
Exp(x)/ALn(x)Raises e to the power of x
ALog(x)Raises 10 to the power of x
eReturns e (base of the natural logarithms)
piReturns pi
sqr(x)Returns x*x
sqrt(x)Returns square root of x
SolveSqr(x2,x,c)Solve a quadrantic equation, the result array may contain complex numbers
SolvePoly(xn,xn-1,....,x,c)/SolvePoly(array)Solve a n degree polynomial, the result array may contain complex numbers
EvalPoly(v,xn,xn-1,....,x,c)/EvalPoly(v,array)Evaluate a polynomial
InterpolateSpline(x,x1,y1,x2,y2,x3,y3,....)/InterpolateSpline(x,Array)Interpolate y from x using spline function
Array(v1,v2,v3,v4)Create a array, first value is placed at index 0
Arrayr(v1,v2,v3,v4)Create a array, last value is placed at index 0
hex/dec/oct/binReturns a hex/dec/oct/bin string of the integer part of the value
cpx(r,i)/complex(r,i)Create a complex number
int(x)Cuts any digits after the point
frac(x)Returns only digits after the point
ComplexAngle(x)Returns the angle of a complex number
ComplexVector(x)Returns the vector length of a complex number
ComplexR(x)Returns the real part of a complex number
ComplexI(x)Returns the complex part of a complex number
StdR(x)/StdC(x)/StdL(x)Round value to standard for specified component
StdE3(x)/.../StdE192(x)Round value to specified standard
FilterLP1(f0,f)Calculate the attenuation in dB for a first order low pass filter with 3 dB frequence f0 at frequence f
FilterHP1(f0,f)Calculate the attenuation in dB for a first order high pass filter with 3 dB frequence f0 at frequence f
FilterLP1cpx(f0,f)Calculate the complex factor for a first order low pass filter with 3 dB frequence f0 at frequence f
FilterHP1cpx(f0,f)Calculate the complex factor for a first order high pass filter with 3 dB frequence f0 at frequence f
RIAA(freq)Convert a frequence to RIAA dB value
RIAAIEC(freq)Convert a frequence to RIAA, with IEC modification dB, value
RIAAcpx(freq)Calculate the complex factor for a frequence according to the RIAA specification "todB(ComplexVector(RIAAcpx(freq)))" is the same as "RIAA(freq)"
RIAAIECcpx(freq)Calculate the complex factor for a frequence according to the RIAA, with IEC modification, specification
CRC8(poly,initial,string)/CRC16(poly,initial,string)/CRC32(poly,initial,string)Calculate crc for specified string. Some standard poly's:
 Poly Initial Test "123456789" Name \$a001* 0 BB3D CRC16 standard crc-16 \$8408 \$ffff 29B1 CRC16 CITT (REMARK: a bitreversal is automatic done when using this poly) \$edb88320* \$ffffffff CBF43926 CRC32 Standard crc-32 (REMARK: output is automatic inverted when using this poly)
All other poly's are calculated without special handling.
*Using 0 as poly will preload this poly and initial value, ie. using crc32(0,0,data) is the same as using crc32(\$edb88320,\$ffffffff,data);
I your need code for crc calculations see CRC calculations
Remark:All these functions are working with inverted poly's, see CRC and Checksum hints for more explanation
CRCPoly(coefficients)Calculate a poly value from a list of coefficients i.e. CRCPoly(16,15,2,0) gives \$a001 as poly value for x^16+x^15+x^2+x^0
CRCPolyReverse(ReversePolyValue)Reverse all bits in poly value. The poly value used here is with lsb coefficient FIRST and msb-1 coefficient last
BoxSurface(x,y,z)Calculates the surface area of a box. To estimate the mass of the box use (for a 10*20*30cm box made of 1mm aluminium): BoxSurface(100m,200m,300m)*1m*aluminium_density
UnitConversion(FromUnit,ToUnit,Value)Convert a value between any two units. Both full and short unit names can be used.
Example: UnitConversion("atm","mmHg",1)
ToSI(Unit,Value)Convert a value to corrosponding SI unit
FromSI(Unit,Value)Convert a value to from corrosponding SI unit
This list is not complete