home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / djgpp / include / builtin.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-25  |  4.0 KB  |  170 lines

  1. /* This is file builtin.h */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1991 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. // This may look like C code, but it is really -*- C++ -*-
  8.  
  9. /* 
  10. Copyright (C) 1988 Free Software Foundation
  11.     written by Doug Lea (dl@rocky.oswego.edu)
  12.  
  13. This file is part of GNU CC.
  14.  
  15. GNU CC is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY.  No author or distributor
  17. accepts responsibility to anyone for the consequences of using it
  18. or for whether it serves any particular purpose or works at all,
  19. unless he says so in writing.  Refer to the GNU CC General Public
  20. License for full details.
  21.  
  22. Everyone is granted permission to copy, modify and redistribute
  23. GNU CC, but only under the conditions described in the
  24. GNU CC General Public License.   A copy of this license is
  25. supposed to have been given to you along with GNU CC so you
  26. can know your rights and responsibilities.  It should be in a
  27. file named COPYING.  Among other things, the copyright notice
  28. and this notice must be preserved on all copies.  
  29. */
  30.  
  31. /*
  32.   arithmetic, etc. functions on built in types
  33. */
  34.  
  35.  
  36. #ifndef _builtin_h
  37. #pragma once
  38. #define _builtin_h 1
  39.  
  40.  
  41. typedef void (*one_arg_error_handler_t)(const char*);
  42. typedef void (*two_arg_error_handler_t)(const char*, const char*);
  43.  
  44.  
  45.  
  46. #include <stddef.h>
  47. #include <std.h>
  48. #include <math.h>
  49.  
  50. long         gcd(long, long);
  51. long         lg(unsigned long); 
  52. double       pow(double, long);
  53. long         pow(long, long);
  54.  
  55. double       start_timer();
  56. #ifdef USE_BUILTIN_DOUBLES
  57. double       return_elapsed_time(double last_time = 0.0);
  58. #endif
  59.  
  60. char*        itoa(long x, int base = 10, int width = 0);
  61. char*        itoa(unsigned long x, int base = 10, int width = 0);
  62. #ifdef __GNUG__
  63. char*        itoa(long long x, int base = 10, int width = 0);
  64. char*        itoa(unsigned long long x, int base = 10, int width = 0);
  65. #endif
  66. char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
  67.  
  68. char*        hex(long x, int width = 0);
  69. char*        hex(unsigned long x, int width = 0);
  70. char*        oct(long x, int width = 0);
  71. char*        oct(unsigned long x, int width = 0);
  72. char*        dec(long x, int width = 0);
  73. char*        dec(unsigned long x, int width = 0);
  74.  
  75. char*        form(const char* fmt, ...);
  76. char*        chr(char ch, int width = 0);
  77. char*        str(const char* s, int width = 0);
  78.  
  79. unsigned int hashpjw(const char*);
  80. unsigned int multiplicativehash(int);
  81. unsigned int foldhash(double);
  82.  
  83. extern void default_one_arg_error_handler(const char*);
  84. extern void default_two_arg_error_handler(const char*, const char*);
  85.  
  86. extern two_arg_error_handler_t lib_error_handler;
  87.  
  88. extern two_arg_error_handler_t 
  89.        set_lib_error_handler(two_arg_error_handler_t f);
  90.  
  91. //#ifdef __OPTIMIZE__
  92.  
  93. #ifdef USE_BUILTIN_DOUBLES
  94. static inline double abs(double arg) 
  95. {
  96.   return (arg < 0.0)? -arg : arg;
  97. }
  98.  
  99. static inline float abs(float arg) 
  100. {
  101.   return (arg < 0.0)? -arg : arg;
  102. }
  103. #endif
  104.  
  105. static inline short abs(short arg) 
  106. {
  107.   return (arg < 0)? -arg : arg;
  108. }
  109.  
  110. static inline long abs(long arg) 
  111. {
  112.   return (arg < 0)? -arg : arg;
  113. }
  114.  
  115. static inline int sign(long arg)
  116. {
  117.   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
  118. }
  119.  
  120. #ifdef USE_BUILTIN_DOUBLES
  121. static inline int sign(double arg)
  122. {
  123.   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
  124. }
  125. #endif
  126.  
  127. static inline long sqr(long arg)
  128. {
  129.   return arg * arg;
  130. }
  131.  
  132. static inline double sqr(double arg)
  133. {
  134.   return arg * arg;
  135. }
  136.  
  137. static inline int even(long arg)
  138. {
  139.   return !(arg & 1);
  140. }
  141.  
  142. static inline int odd(long arg)
  143. {
  144.   return (arg & 1);
  145. }
  146.  
  147. static inline long lcm(long x, long y)
  148. {
  149.   return x / gcd(x, y) * y;
  150. }
  151.  
  152. static inline void setbit(long& x, long b)
  153. {
  154.   x |= (1 << b);
  155. }
  156.  
  157. static inline void clearbit(long& x, long b)
  158. {
  159.   x &= ~(1 << b);
  160. }
  161.  
  162. static inline int testbit(long x, long b)
  163. {
  164.   return ((x & (1 << b)) != 0);
  165. }
  166.  
  167. //#endif
  168.  
  169. #endif
  170.