Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

builtin.h

Go to the documentation of this file.
00001 // This may look like C code, but it is really -*- C++ -*-
00002 
00003 /* 
00004 Copyright (C) 1988, 1992 Free Software Foundation
00005     written by Doug Lea (dl@rocky.oswego.edu)
00006 
00007 This file is part of the GNU C++ Library.  This library is free
00008 software; you can redistribute it and/or modify it under the terms of
00009 the GNU Library General Public License as published by the Free
00010 Software Foundation; either version 2 of the License, or (at your
00011 option) any later version.  This library is distributed in the hope
00012 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00013 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014 PURPOSE.  See the GNU Library General Public License for more details.
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   arithmetic, etc. functions on built in types
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                                 // Otherwise, see myenv.h
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 /* hpux and SCO define this in math.h */
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 

Generated on Wed Dec 15 21:20:28 2004 for vuVolume by  doxygen 1.3.9.1