• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/lib/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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 
00019 Linking this file statically or dynamically with other modules is making
00020 a combined work based on this file.  Thus, the terms and conditions of
00021 the GNU General Public License cover the whole combination.
00022 
00023 In addition, as a special exception, the copyright holders of this file
00024 give you permission to combine this file with free software programs or
00025 libraries that are released under the GNU LGPL and with code included in
00026 the standard release of ns-2 under the Apache 2.0 license or under
00027 otherwise-compatible licenses with advertising requirements (or modified
00028 versions of such code, with unchanged license).  You may copy and
00029 distribute such a system following the terms of the GNU GPL for this
00030 file and the licenses of the other code concerned, provided that you
00031 include the source code of that other code when and as the GNU GPL
00032 requires distribution of source code.
00033 
00034 Note that people who make modified versions of this file are not
00035 obligated to grant this special exception for their modified versions;
00036 it is their choice whether to do so.  The GNU General Public License
00037 gives permission to release a modified version without this exception;
00038 this exception also makes it possible to release a modified version
00039 which carries forward this exception.
00040 */
00041 
00042 /*
00043   arithmetic, etc. functions on built in types
00044 */
00045 
00046 
00047 #ifndef _builtin_h
00048 #ifdef __GNUG__
00049 #pragma interface
00050 #endif
00051 #define _builtin_h 1
00052 
00053 #include <stddef.h>
00054 // #include <std.h>
00055 // #include <cmath>
00056 #include <stdio.h>
00057 
00058 #ifndef __GNUC__
00059 #define __attribute__(x)
00060 #endif
00061 
00062 typedef void (*one_arg_error_handler_t)(const char*);
00063 typedef void (*two_arg_error_handler_t)(const char*, const char*);
00064 
00065 long         gcd(long, long);
00066 long         lg(unsigned long); 
00067 double       pow(double, long);
00068 long         pow(long, long);
00069 
00070 extern "C" double       start_timer();
00071 extern "C" double       return_elapsed_time(double last_time = 0.0);
00072 
00073 char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
00074 
00075 unsigned int hashpjw(const char*);
00076 unsigned int multiplicativehash(int);
00077 unsigned int foldhash(double);
00078 
00079 extern void default_one_arg_error_handler(const char*) __attribute__ ((noreturn));
00080 extern void default_two_arg_error_handler(const char*, const char*) __attribute__ ((noreturn));
00081 
00082 extern two_arg_error_handler_t lib_error_handler;
00083 
00084 extern two_arg_error_handler_t 
00085        set_lib_error_handler(two_arg_error_handler_t f);
00086 
00087 
00088 #if !defined(IV)
00089 
00090 inline short abs(short arg) 
00091 {
00092   return (arg < 0)? -arg : arg;
00093 }
00094 
00095 inline int sign(long arg)
00096 {
00097   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
00098 }
00099 
00100 inline int sign(double arg)
00101 {
00102   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
00103 }
00104 
00105 inline long sqr(long arg)
00106 {
00107   return arg * arg;
00108 }
00109 
00110 #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
00111 inline double sqr(double arg)
00112 {
00113   return arg * arg;
00114 }
00115 #endif
00116 
00117 inline int even(long arg)
00118 {
00119   return !(arg & 1);
00120 }
00121 
00122 inline int odd(long arg)
00123 {
00124   return (arg & 1);
00125 }
00126 
00127 inline long lcm(long x, long y)
00128 {
00129   return x / gcd(x, y) * y;
00130 }
00131 
00132 inline void (setbit)(long& x, long b)
00133 {
00134   x |= (1 << b);
00135 }
00136 
00137 inline void clearbit(long& x, long b)
00138 {
00139   x &= ~(1 << b);
00140 }
00141 
00142 inline int testbit(long x, long b)
00143 {
00144   return ((x & (1 << b)) != 0);
00145 }
00146 
00147 #endif
00148 #endif

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1