home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / cplusinc / builtin.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-13  |  3.5 KB  |  161 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1988, 1992 Free Software Foundation
  5.     written by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*
  21.   arithmetic, etc. functions on built in types
  22. */
  23.  
  24.  
  25. #ifndef _builtin_h
  26. #ifdef __GNUG__
  27. #pragma interface
  28. #endif
  29. #define _builtin_h 1
  30.  
  31. #include <stdio.h>
  32. #include <stddef.h>
  33. #include <std.h>
  34. #include <math.h>
  35.  
  36. #ifdef __GNUG__
  37. #define _VOLATILE_VOID volatile void
  38. #else
  39. #define _VOLATILE_VOID void
  40. #endif
  41.  
  42. typedef void (*one_arg_error_handler_t)(const char*);
  43. typedef void (*two_arg_error_handler_t)(const char*, const char*);
  44.  
  45. long         gcd(long, long);
  46. long         lg(unsigned long); 
  47. double       pow(double, long);
  48. long         pow(long, long);
  49.  
  50. extern "C" double       start_timer();
  51. extern "C" double       return_elapsed_time(double last_time = 0.0);
  52.  
  53. char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
  54.  
  55. unsigned int hashpjw(const char*);
  56. unsigned int multiplicativehash(int);
  57. unsigned int foldhash(double);
  58.  
  59. extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
  60. extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
  61.  
  62. extern two_arg_error_handler_t lib_error_handler;
  63.  
  64. extern two_arg_error_handler_t 
  65.        set_lib_error_handler(two_arg_error_handler_t f);
  66.  
  67.  
  68. double abs(double arg);
  69. float abs(float arg);
  70. short abs(short arg);
  71. long abs(long arg);
  72. int sign(long arg);
  73. int sign(double arg);
  74. long sqr(long arg);
  75. double sqr(double arg);
  76. int even(long arg);
  77. int odd(long arg);
  78. long lcm(long x, long y);
  79. void (setbit)(long& x, long b);
  80. void clearbit(long& x, long b);
  81. int testbit(long x, long b);
  82.  
  83. #if !defined(IV)
  84.  
  85. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  86. inline double abs(double arg) 
  87. {
  88.   return (arg < 0.0)? -arg : arg;
  89. }
  90. #endif
  91.  
  92. inline float abs(float arg) 
  93. {
  94.   return (arg < 0.0)? -arg : arg;
  95. }
  96.  
  97. inline short abs(short arg) 
  98. {
  99.   return (arg < 0)? -arg : arg;
  100. }
  101.  
  102. inline long abs(long arg) 
  103. {
  104.   return (arg < 0)? -arg : arg;
  105. }
  106.  
  107. inline int sign(long arg)
  108. {
  109.   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
  110. }
  111.  
  112. inline int sign(double arg)
  113. {
  114.   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
  115. }
  116.  
  117. inline long sqr(long arg)
  118. {
  119.   return arg * arg;
  120. }
  121.  
  122. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  123. inline double sqr(double arg)
  124. {
  125.   return arg * arg;
  126. }
  127. #endif
  128.  
  129. inline int even(long arg)
  130. {
  131.   return !(arg & 1);
  132. }
  133.  
  134. inline int odd(long arg)
  135. {
  136.   return (arg & 1);
  137. }
  138.  
  139. inline long lcm(long x, long y)
  140. {
  141.   return x / gcd(x, y) * y;
  142. }
  143.  
  144. inline void (setbit)(long& x, long b)
  145. {
  146.   x |= (1 << b);
  147. }
  148.  
  149. inline void clearbit(long& x, long b)
  150. {
  151.   x &= ~(1 << b);
  152. }
  153.  
  154. inline int testbit(long x, long b)
  155. {
  156.   return ((x & (1 << b)) != 0);
  157. }
  158.  
  159. #endif
  160. #endif
  161.