00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _builtin_h
00026 #ifdef __GNUG__
00027 #pragma interface
00028 #endif
00029 #define _builtin_h 1
00030
00031 #include <stddef.h>
00032 #include "std.h"
00033 #include <math.h>
00034
00035 #ifdef __GNUG__
00036 #include <cmath>
00037 #endif
00038
00039 namespace linalg
00040 {
00041 using namespace linalg;
00042
00043 #ifdef __GNUG__
00044 #define _VOLATILE_VOID volatile void
00045 #else
00046 #define _VOLATILE_VOID void
00047 #endif
00048
00049 long gcd(long, long);
00050 long lg(unsigned long);
00051
00052
00053 #if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 8)
00054 extern "C" double start_timer();
00055 extern "C" double return_elapsed_time(double last_time = 0.0);
00056 #endif
00057
00058 #if defined(linux)
00059 inline div_t div(int numer, int denom)
00060 { const div_t res = { numer/denom, numer%denom}; return res;}
00061 #endif
00062
00063 char* dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
00064
00065 unsigned int hashpjw(const char*);
00066 unsigned int multiplicativehash(int);
00067 unsigned int foldhash(double);
00068
00069
00070 #if !defined(IV)
00071
00072 #ifndef __GNUG__ // has been defined in <cmath>
00073 inline double abs(double arg)
00074 {
00075 return (arg < 0.0)? -arg : arg;
00076 }
00077
00078 inline float abs(float arg)
00079 {
00080 return (arg < 0.0)? -arg : arg;
00081 }
00082 #endif
00083
00084 inline short abs(short arg)
00085 {
00086 return (arg < 0)? -arg : arg;
00087 }
00088
00089 #ifndef __GNUG__ // has been defined in <cstdlib>
00090 inline long abs(long arg)
00091 {
00092 return (arg < 0)? -arg : arg;
00093 }
00094 #endif
00095
00096 inline int sign(long arg)
00097 {
00098 return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
00099 }
00100
00101 inline int sign(double arg)
00102 {
00103 return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
00104 }
00105
00106 static inline long sqr(long arg)
00107 {
00108 return arg * arg;
00109 }
00110
00111 #if ! _G_MATH_H_INLINES
00112 static inline double sqr(double arg)
00113 {
00114 return arg * arg;
00115 }
00116 #endif
00117
00118 inline int even(long arg)
00119 {
00120 return !(arg & 1);
00121 }
00122
00123 inline int odd(long arg)
00124 {
00125 return (arg & 1);
00126 }
00127
00128 inline long lcm(long x, long y)
00129 {
00130 return x / gcd(x, y) * y;
00131 }
00132
00133 inline void (setbit)(long& x, long b)
00134 {
00135 x |= (1 << b);
00136 }
00137
00138 inline void clearbit(long& x, long b)
00139 {
00140 x &= ~(1 << b);
00141 }
00142
00143 inline int testbit(long x, long b)
00144 {
00145 return ((x & (1 << b)) != 0);
00146 }
00147
00148 #if !defined(M_PI)
00149 # define M_PI 3.14159265358979323846
00150 #endif
00151
00152 }
00153 #endif
00154 #endif
00155