Purpose

Provide additional math functions.

Overview

In the course of implementing QuakeScheme and integrating Ogg Vorbis, I had need for additional math functions not provided in bg_lib.c nor q_math.c.

The file q_math.c is not supposed to be modified (which presumably includes adding functions), so I created a new file.

Usage

Additional math functions provided are:

Limitations

The logarithmic functions are horridly inaccurate (e.g. 2^5 == exp(5*log(2)) => 32.000003).

The complete set of functions in math.h is not provided.

Programming Notes

Q_sin, Q_cos, Q_atan2, and Q_sqrt are just wrappers around the provided syscalls.

Antilogarithm is calculated using a 1024-element antilogarithm lookup table and linear interpolation. The 1024 elements span the domain 1 to e. The range is thus from 0.0 to 1.0. Logarithm is calculated by searching the other side of the table.

Logarithmic functions were developed before the rest of bg_math.c, which is why logs are separated from the rest. The log lookup table (lntable.frag) was programmatically generated.


(2002.02.23)

Files:

Or as a tarball: bg_math-20020223.tar.gz (35KB) ("polluting" form)
-- PhaethonH (phaethon@linux.ucla.edu)