________________________________________________________________ VPCalc Documentation, Part 3 ________________________________________________________________ Functions - Functions are used on the right hand side of an equation or assignment statement. Functions do not change the value of their arguments, but produce a single result that can be used to further complete the evaluation of the expression that contains the function reference. If a statement starts with a function reference like a procedure, then the function is evaluated and this value is assigned to the current active item. Abs(X) = AbsoluteValue(X): Absolute value function = |X|. ACos(X) = ArcCoSine(X): Inverse of Trigonometric CoSine function, error if |X| > 1. If the degree mode is set, the answer, A, will be in the range 0 <= A <= 180. If the radian mode is set, the answer will be in the range 0 <= A <= Pi. ACosH(X) = ArcHyperbolicCoSine(X): The positive inverse of Hyperbolic CoSine function, error if X < 1. ASin(X) = ArcSin(X): Inverse of Trigonometric Sine function, error if |X| > 1. If the degree mode is set, the answer, A, will be in the range -90 <= A <= 90. If the radian mode is set, the answer will be in the range -Pi/2 <= A <= Pi/2. ASinH(X) = ArcHyperbolicSine(X): Inverse of Hyperbolic Sine function. ATan(X) = ArcTangent(X): Inverse of Trigonometric Tangent function. If the degree mode is set, the answer, A, will be in the range -90 <= A <= 90. If the radian mode is set, the answer will be in the range -Pi/2 <= A <= Pi/2. ATan2(Y' X) = ArcTangent(Y over X): Trigonometric ArcTangent function. Used to find the Polar coordinates angle coordinate of the Cartesian coordinates (X, Y). If the degree mode is set, the answer, A, will be in the range -180 < A <= 180. If the radian mode is set, the answer will be in the range -Pi < A <= Pi. If both X and Y are zero, an answer of zero will be given. ATanH(X) = ArcHyperbolicTangent(X): Inverse of Hyperbolic Tangent function, error if|X| >= 1. Cos(X) = CoSine(X): Trigonometric CoSine function, error if |X| is very large. CosH(X) = HyperbolicCoSine(X): Hyperbolic CoSine function. Exp(X) = eToThePower(X): Evaluates to e raised to the X power, where e is the base of the natural logarithms. The item Ln10 = Ln(10) is put on the list when needed by the exponential functions. If Ln10 is not on the list, the file Ln10.VPN is read-in and Ln10 added to the list. If the file Ln10.VPN is not found, Ln10 is computed. ExpL(X) = eToThePower(X) - 1: Evaluates to one less than e raised to the X power, where e is the base of the natural logarithms. This function is needed when an expression contains Exp(X) - 1 and X can take on small values. ExpL(X) is accurate for small X. Fac(X) = Factorial of Int(X): Factorial function = 1 * 2 * 3 * ... * X. Only the integer portion of X is used in the calculation. Frac(X) = FractionalPart(X): Fractional part function. Frac(X) = X - Int(X). GCD(X' Y) = Greatest Common Divisor: Greatest common divisor function. Uses the oldest algorithm in the book, Euclid's algorithm (see Euclid's Elements, Book 7, Proposi- tions 1 and 2). Only the integer parts of X and Y are used in the computation. For example, the GCD of 12 and 18 is 6. Int(X) = IntegerPart(X): Integer part function. For X >= 0, Int(X) is the largest integer less than or equal to X. Int(-X) = -Int(X); Inv(X) = 1 / X: Inverse or reciprocal function, 1.0 divided by X, error if X = 0. Ln(X) = NaturalLog(X): Evaluates to the Log base e of X, where e is the base of the natural logarithms, error if X <= 0. LnL(X) = NaturalLog(X + 1): Evaluates to the Log base e of (X + 1), where e is the base of the natural logarithms, error if X <= -1. This function is needed when an expression contains Ln(X + 1) and X can take on a value near zero. ExpL(X) is accurate for values of X near zero. Log(X) = LogBase10(X): Evaluates to the Log base 10 of X, error if X <= 0. Lop(X) = ReducePrecision(X): This function evaluates to X with its least significant super-digit removed. If rounding is turned on, the removed super-digit is used to round into the new least significant super-digit. In VPCalc numbers are normalized from both sides. If a calculation results in a number with some trailing zero bytes, these bytes are removed by reducing the count of the number of bytes in the mantissa, and memory is reallocated. The Lop function can result in many bytes being removed if removing one byte results in many trailing zeros. Mag(X' Y) = SqRt(Sq(X), Sq(Y)): Magnitude of (Y, X) function Used to find the Polar coordinates radius coordinate of the Cartesian coordinates (X, Y). Mod(X' Y) = X - (Int(X/Y) * Y): Modulo function. Mod(X' Y) = X - (Int(X/Y) * Y). Where Int(X/Y) is the integer part of X/Y. The sign of Mod(X' Y) is equal to the sign of X. An error message is generated if Y = 0. PowM(X' Y) = (X to the power Y) Mod FMB: The Exponential function with modulo arithmetic. This function operates differently depending on whether Y is an exact integer. If Y is an exact integer, the peasants' method is used in which up to 2 * Log base 2 of Y multiplies of powers of X are done to compute the result. The Modulo process is performed after each multiply to prevent the intermediate results from becoming large. If Y is not an exact integer, the result is computed by Exp(Y * Ln(X)) Mod FMB. If FMB is not on the list, it is added to the list with a value of zero. If FMB is zero, the Modulo is not performed. An error message is generated in three cases: 1) X is < 0 and Y is not an integer. 2) X = 0 and Y is < 0. 3) X = 0 and Y = 0. RN(X) = RandomNumber(Seed=X): Random number function. RN(X) evaluates to a random number between zero and 1.0. This number will never have more than 35 decimal digits. Theoretically the random number generator will cycle after 10 ** 35 numbers, but the earth will not last that long. The fractional part of the argument of the function is taken as the seed of the random number generator. For a consecutive set of random numbers, the argument X should be the previous random number generated. The items RNA and RNC are put on the list by the random number function. The equation used is: RN(X) = (RNA * X * 10^35 + RNC) mod (10^35) / 10^35, where RNA and RNC are 35 digit integers. Sin(X) = Sine(X): Trigonometric Sine function, error if |X| is very large. SinH(X) = HyperbolicSine(X) Hyperbolic Sine function. Sq(X) = X Squared: The square function, X times X. SqRt(X) = SquareRoot(X): The positive square root function, error if X < 0. Tan(X) = Tangent(X): Trigonometric Tangent function, error if |X| is very large. It is also an error if X is equivalent to plus or minus 90 degrees. TanH(X) = HyperbolicTangent(X): Hyperbolic Tangent function. ToDeg(X) = RadiansToDegrees(X): Converts radians to degrees. Evaluates to X multiplied by 180/Pi. ToRad(X) = DegreesToRadians(X): Converts degrees to radians. Evaluates to X multiplied by Pi/180. -X = Negative of X, 0 - X: Negative inverse of X. The -, +, and ! functions do not require the parentheses so they also can be considered as unary or monadic operators. +X = Positive of X, 0 + X: The identity operator, +X = X. !X = Not X, 0 -> 1 else 0: Logical Not operator. Not X (!!X) will leave 0.0 alone and will change all other values to 1.0 (True). If, GoTo, GoUpTo, Label, Continuation lines - The following commands are primarily for use in VPCalc code files, but can be used from the Command: prompt line. If Command: The If command is the first word of an If statement. The syntax of the If statement is: If Then Else The expression following the If is evaluated and if it is True, i.e., not zero, all statements on the same line following the next Else are deleted and execution continues with the statements following the Then. If the expression evaluates to zero (False), all statements following the expression up to the next Else are deleted and execution continues with the statements following the next Else. The Then key word is optional, the Then is optional and the Else is optional. The equivalent of a case statement can be constructed for example like: If A=1 B=3 Else If A=2 B=5 Else If A=3 B=7 Else B=0 If A is an integer, this is equivalent to: B=0 If (1 <= A) & (A <= 3) Then B=2*A+1 GoTo Command: The GoTo