User's Guide to the GNU C++ Class Library - Builtin

Node: Builtin Next: New Prev: Headers Up: Top

Utility functions for built in types

Files `builtin.h' and corresponding `.cc' implementation files contain various convenient inline and non-inline utility functions. These include useful enumeration types, such as TRUE , FALSE ,the type definition for pointers to libg++ error handling functions, and the following functions.

long abs(long x); double abs(double x);
inline versions of abs. Note that the standard libc.a version, int abs(int) is not declared as inline.

void clearbit(long& x, long b);
clears the b'th bit of x (inline).

void setbit(long& x, long b);
sets the b'th bit of x (inline)

int testbit(long x, long b);
returns the b'th bit of x (inline).

int even(long y);
returns true if x is even (inline).

int odd(long y);
returns true is x is odd (inline).

int sign(long x); int sign(double x);
returns -1, 0, or 1, indicating whether x is less than, equal to, or greater than zero (inline).

long gcd(long x, long y);
returns the greatest common divisor of x and y.

long lcm(long x, long y);
returns the least common multiple of x and y.

long lg(long x);
returns the floor of the base 2 log of x.

long pow(long x, long y); double pow(double x, long y);
returns x to the integer power y using via the iterative O(log y) ``Russian peasant'' method.

long sqr(long x); double sqr(double x);
returns x squared (inline).

long sqrt(long y);
returns the floor of the square root of x.

unsigned int hashpjw(const char* s);
a hash function for null-terminated char* strings using the method described in Aho, Sethi, & Ullman, p 436.

unsigned int multiplicativehash(int x);
a hash function for integers that returns the lower bits of multiplying x by the golden ratio times pow(2, 32). See Knuth, Vol 3, p 508.

unsigned int foldhash(double x);
a hash function for doubles that exclusive-or's the first and second words of x, returning the result as an integer.

double start_timer()
Starts a process timer.

double return_elapsed_time(double last_time)
Returns the process time since last_time. If last_time == 0 returns the time since the last start_timer. Returns -1 if start_timer was not first called.

File `Maxima.h' includes versions of MAX, MIN for builtin types.

File `compare.h' includes versions of compare(x, y) for builtin types. These return negative if the first argument is less than the second, zero for equal, and positive for greater.


Next: New Up: Top