Next: Random Numbers Up: Programming Utilities Previous: Global Variables

Numerical Utilities

A small set of useful numerical functions are provided:


public  BOOLEAN  numerically_close(
    Real  n1,
    Real  n2,
    Real  threshold_ratio )

Checks if the two numbers are within the given threshold ratio. For instance, numerically_close( 4113.0, 4112.0, 0.001 ) returns TRUE, since the two numbers are with 0.1 percent of each other.


public  Real  get_good_round_value(
    Real    value )

Returns the largest power of 10 or five times a power of 10 which is less then the specified value. Useful for determining graph axis positions.


public  int  solve_quadratic(
    Real   a,
    Real   b,
    Real   c,
    Real   *root1,
    Real   *root2 )

Finds the real roots of the equation . Returns either 0, 1, or 2, indicating the number of unique real roots, which are passed back either in the argument root1, or in both arguments, root1 and root2.


public  int solve_cubic(
    Real   a,
    Real   b,
    Real   c,
    Real   d,
    Real   roots[ 3 ] )

Finds the real roots of the equation . Returns the number of unique real solutions, and passes them back in the array roots.


public  Real  evaluate_polynomial(
    int     n,
    Real    poly[],
    Real    u )

Efficiently evaluates a polynomial of the form , using Horner's rule.



Next: Random Numbers Up: Programming Utilities Previous: Global Variables


david@pet.mni.mcgill.ca
Fri Feb 17 15:40:04 EST 1995