Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

builtin.h

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 #if ! defined(TWINE)
00028     #pragma interface
00029 #endif
00030 #endif
00031 #define _builtin_h 1
00032 
00033 #include <stddef.h>
00034 #include <math.h>
00035 
00036 #ifdef __GNUG__
00037 #include <cmath>
00038 #endif
00039 
00040 #ifdef __GNUG__
00041 #define _VOLATILE_VOID volatile void
00042 #else
00043 #define _VOLATILE_VOID void
00044 #endif
00045 
00046 typedef void (*one_arg_error_handler_t)(const char*);
00047 typedef void (*two_arg_error_handler_t)(const char*, const char*);
00048 
00049 long         gcd(long, long);
00050 long         lg(unsigned long);
00051 double       pow(double, long);
00052 long         pow(long, long);
00053 
00054 #ifdef __GNUG__                 // Otherwise, see myenv.h
00055 extern "C" double       start_timer();
00056 extern "C" double       return_elapsed_time(double last_time = 0.0);
00057 #endif
00058 
00059 char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
00060 
00061 unsigned int hashpjw(const char*);
00062 unsigned int multiplicativehash(int);
00063 unsigned int foldhash(double);
00064 
00065 extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
00066 extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
00067 
00068 extern two_arg_error_handler_t lib_error_handler;
00069 
00070 extern two_arg_error_handler_t
00071        set_lib_error_handler(two_arg_error_handler_t f);
00072 
00073 
00074 #if !defined(IV)
00075 
00076 #if !defined(__GNUG__) && !defined(__xlC__)             // has been defined in <cmath>
00077 inline double abs(double arg)
00078 {
00079   return (arg < 0.0)? -arg : arg;
00080 }
00081 
00082 inline float abs(float arg)
00083 {
00084   return (arg < 0.0)? -arg : arg;
00085 }
00086 #endif
00087 
00088 inline short abs(short arg)
00089 {
00090   return (arg < 0)? -arg : arg;
00091 }
00092 
00093 #ifndef __GNUG__                // has been defined in <cstdlib>
00094 inline long abs(long arg)
00095 {
00096   return (arg < 0)? -arg : arg;
00097 }
00098 #endif
00099 
00100 inline int sign(long arg)
00101 {
00102   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
00103 }
00104 
00105 inline int sign(double arg)
00106 {
00107   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
00108 }
00109 
00110 inline long sqr(long arg)
00111 {
00112   return arg * arg;
00113 }
00114 
00115 #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
00116 inline double sqr(double arg)
00117 {
00118   return arg * arg;
00119 }
00120 #endif
00121 
00122 //inline int even(long arg)
00123 //{
00124 //  return !(arg & 1);
00125 //}
00126 
00127 //inline int odd(long arg)
00128 //{
00129 //  return (arg & 1);
00130 //}
00131 
00132 inline long lcm(long x, long y)
00133 {
00134   return x / gcd(x, y) * y;
00135 }
00136 
00137 inline void (setbit)(long& x, long b)
00138 {
00139   x |= (1 << b);
00140 }
00141 
00142 inline void clearbit(long& x, long b)
00143 {
00144   x &= ~(1 << b);
00145 }
00146 
00147 inline int testbit(long x, long b)
00148 {
00149   return ((x & (1 << b)) != 0);
00150 }
00151 
00152 #endif
00153 #endif

Generated on Tue Feb 17 02:03:02 2004 for harlem by doxygen 1.3.6