-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhandy.h
51 lines (42 loc) · 1.52 KB
/
handy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __HANDY
#define __HANDY 1
/* Two new control structures for C. Yay! */
#define loop for (;;)
#define loopend(x) {if(x)break;}
/* Usage: do { ... } until (boolean); */
#define until(a) while (!(a))
/* Some basic data types */
/* typedef unsigned char CHAR; Is this a typo */
typedef unsigned char UCHAR;
typedef unsigned int UINT;
typedef unsigned long ULONG;
typedef enum {FALSE, TRUE} BOOL;
/* Random number stuff that SHOULD have been there */
#include <time.h>
#include <stdio.h> /* Needed for NULL * */
#include <stdlib.h>
#define RANDOMIZE() (srand((UINT)time( (time_t *)NULL )))
/* This is skewed due to integer division, but
* good enough when a is much smaller than RAND_MAX.
*/
#define RANDOM(a) (rand() / (RAND_MAX / (a) + 1))
#if 0
/* Unused, won't compile on recent gcc due to multiple definitions */
/* Mini-benchmarking tools. Only one second accuracy */
time_t __HANDY_BENCH;
#define START() (__HANDY_BENCH = time (& __HANDY_BENCH))
#define MARK() ((long)time ((time_t *)0) - __HANDY_BENCH)
#endif
/* Stuff that's already there, but is faster as a MACRO */
#define MIN(a,b) (((a) < (b)) ? (a) : (b) )
#define MAX(a,b) (((a) > (b)) ? (a) : (b) )
#define ABS(a) (((a) < 0 ) ? -(a) : (a) )
#define FABS(a) (((a) < F 0) ? -(a) : (a) )
#define DABS(a) (((a) < 0.0) ? -(a) : (a) )
#define SIGN(a) (((a) < 0 ) ? -1 : 1 )
#define FSIGN(a) (((a) < F 0) ? F(-1): F 1 )
#define DSIGN(a) (((a) < 0.0) ? -1.0 : 1.0 )
/* This seems nifty to me */
#define DONE 1
#define NOT_DONE 0
#endif