The Math Library: 1.1 Basic Math Functions: Algebraic Functions

Up: GEOS SDK TechDocs | Up | Prev: 1 Basic Math Functions | Next: 1.2 Transcendental Functions

Algebraic routines perform algebraic operations on FP numbers. The Math Library provides all of the basic algebraic routines that operate on GEOS FP numbers (addition, subtraction, etc.).

If you wish to call these routines directly rather than rely on the C operations, you may manipulate the floating point stack directly. To add two numbers using FloatAdd() for example, you would use FloatPushNumber() twice to push the two values to add onto the FP stack, and then call FloatAdd() to operate on the FP stack. (See Adding Two FP Numbers .)

Code Display D-2 Adding Two FP Numbers

/*
 * The following two methods each add two FP numbers and return the result. The 
 * first method is familiar C code. The second example uses the floating point 
 * routines from math.h directly. Note that the C code will be assembled into code 
 * that uses FloatAdd() also, but that this is transparent to the code.
 */
@method MyProcessClass, MSG_SUM_FLOATS {
    long double			number1, number2, number3;
    number1 = 1.0;
    number2 = 2.0;
    number3 = number1 + number2;
    return(number3);
}
@method MyProcessClass, MSG_SUM_FLOATS_MANUALLY {
    long double			number1, number2, number3;
    number1 = 1.0;
    number2 = 2.0;
    FloatPushNumber(&number1);				/* Push number1 onto the FP stack. */
    FloatPushNumber(&number2);				/* Push number2 onto the FP stack. */
    FloatAdd();				/* Add the top two numbers on the FP stack. The
				 * result will be placed on top of the FP stack.*/
    FloatPopNumber(&number3);				/* Pop the result into the number3 variable. */
    return(number3);
}

Several functions have no equivalent C operation. Consult Direct FP Operations for more details on using these functions.

Note that although direct comparisons between FP numbers are not allowed, you can use the FloatLt0(), FloatGt0(), and FloatEq0() functions to compare whether the the addition of two FP numbers is gretaer than, less than, or equal to zero.


Up: GEOS SDK TechDocs | Up | Prev: 1 Basic Math Functions | Next: 1.2 Transcendental Functions