Main Page | Class List | File List | Class Members | File Members

between.c

Go to the documentation of this file.
00001 #include "standard.h"
00002 #include "error.h"
00003 
00004 /*
00005  * Function to compute if another number is between two numbers on a mod 32 scale 
00006  */
00007 
00008 int between(int x,int low, int high)
00009 /* 
00010  * returns 1 if x is between low and high on a mod 32 scale (ie. circular)
00011  * returns 0 if not
00012  * ie. 5 is between 30 and 6.
00013  *     7 is not between 30 and 6
00014  */
00015 {
00016   if (high < low)
00017     return (x>low || x<high);
00018   else 
00019     return (x<high && x>low);
00020 }
00021 
00022 int minus(int a, int b)
00023 /*
00024  * returns a - b on a mod 32 scale.  
00025  * ie. minus(5,4) == 1
00026  *     minus(5,6) == 31
00027  */
00028 {
00029   if ((a>31) || (b>31) || (a<0) || (b<0))
00030     error("minus","Non mod 32 numbers passed to mod 32 minus routine");
00031   if(b<=a)
00032     return (a-b);
00033   else
00034     return (32-(b-a));
00035 }
00036 
00037 #if(0)
00038 int main()
00039 {
00040   int x, y;
00041   while (1) {
00042     printf("Enter x, y: ");
00043     scanf("%d %d",&x,&y);
00044     printf("x - y = %d",minus(x,y));
00045   }
00046 }
00047 #endif

Generated on Sun Jul 16 16:27:45 2006 by  doxygen 1.3.9.1