Clac — The Manual

Eero Tamminen

Version 1.10 10. November 1994

1 Name

clac() — an expression evaluation function.

2 Description

Clac calculates expressions following the precedence (order of operations). Functions and variables are case-insensitive for the user’s convenience. The parser catches common mistakes like unmatched parenthesis or divide by zero and returns an appropriate error code in the communication structure. Unrecognized characters produce also an error code.

3 Operators

Recognized characters and operators: |, &: Bitwise OR and AND operators. >, <: Operators for shifting bits right and left. +, –: Addition and subtraction operators.

%: Modulo operator. ∗, /: Multiply and divide operators.

ˆ : Exponentiation operator. +, –: Signs. Signed numbers should be in parenthesis. (, ): Parenthesis.

.: Decimal point.

,: Used to separate multiple fuction arguments. zi: Value z is imaginary (but nevertheless, accounted for ;-))). zp: Value z is a percentage (50p = 0.05, (not $0.05 :-)). z!: Value z is a factorial (4! = 1 ∗ 2 ∗ 3 ∗ 4). ’z: Value z is in binary format. #z: Value z is in octal format.

$z, 0xz: Value z is in hexadecimal format. ”z: Value z is in ascii format. ;: Used to separate comment from an expression.

Decimal numbers can have exponent notation (ie. a number immediatly followed by ’e’ and a number). Eg. 1e2 = 1∗10^{2} and 5e−1 = 5∗10^{−1} = 0.5. Exponent has to be an integer.

Operators &, |, >, < ,% and ! manipulate only real numbers (or complex number’s real parts). Operator ‘ˆ ’s second parameter (power) should be a real number. All other parameters can be either real or complex numbers.

4 Functions with Single Argument

ln(x): Natural logarithm of x. lg(x): Logarithm of x in base 10.

deg(x): Convert x radians to degrees. rad(x): Convert x degrees to radians. sin(x): Sine of x. cos(x): Cosine of x. tan(x): Tangent of x. asin(x): Arcus sine of x. acos(x): Arcus cosine of x. atan(x): Arcus tangent of x. sinh(x): Hyperbolic sine of x. cosh(x): Hyperbolic cosine of x. tanh(x): Hyperbolic tangent of x. sqrt(x): Square root of x. rnd(x): A random number between 0 and x. abs(x): Absolute value of x. int(x): Integer part of x. frac(x): Fraction part of x. real(x): Real part of (a complex number) x. imag(x): Imaginary part of (a complex number) x.

5 Functions with Multiple Arguments

rtop(a, b): Convert a rectangular co-ordinate to a polar one. A could be a complex number (real and imaginary components) or a and b could both be real numbers.

ptor(a, b): Convert a polar co-ordinate to a rectangular one. A could be a complex number (a vector) or a and b could both be real numbers. Direction is supposed to be in radians. over(n, k): The number of k component group combinations in n components

\binom{n}{k} = \frac{n!}{k!(n−k)!}.

root(n, x): N^{th} root of x.

min(a, b, c): Smallest nuber of a, b, c.

max(a, b, c): Largest number of a, b, c.

avg(a, b, c): Average of numbers a, b, c.

std(a, b, c): Standard deviation (\sqrt{∑(x_{i} − \overline{x})^{2}/n} ) of numbers a, b, c.

Only functions real(), imag(), rtop() and ptor() manipulate imaginary parts of complex numbers.

Number of arguments is unlimited in the min(), max(), avg() and std() functions.

6 Examples

• $F F.8 − ((”ET ∗ 12) + 5)/3.7 + (−1)

• (1 + 2i) ∗ (2 + 1i)

• 0.45 − sin(rad(45))i

7 Hints

• You can use ptor(lenght, angle) to input complex numbers in polar co-ordinates. If you want to input angles in degrees, use rad(angle).

• With real(rtop(a + bi)) or sqrt(a + bi) you can get the absolute values of inputted complex numbers.

8 Limitations

• Values are internally calculated using double precision numbers.

• No overflow check.

9 Bugs

Probably. Let’s hope they aren’t too serious… In any case, report them to me.

10 Development

Clac was programmed with MicroEmacs and Everest (v. 3.0 → 3.3) editors and Sozobon C (v. 1.4 → 2.0X). Some debugging was done with GNU C (v. 2.3.3 and 2.5.8) and GNU Emacs editor (v. 18.58).

11 Thanks to

• Jarkko Kniivilä, who advised me on C syntax.

• Gernot Saltzer for bugreports and suggestions.

• Jürgen Lock, who patiently answered to my mail.

• Helpful people on #atari (irc), whom I have chatted with: Dirch, Gryf, Infy, Aviva…

12 Copyright

Eero Tamminen / puujalka (irc), t150315@cc.tut.fi. Freeware.