appletmath.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletmath.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletdefs.h"
00008 #include "appletmath.h"
00009 
00010 
00011 long divup (long n, long d) {
00012     
00013     /*
00014     divide numerator n by divisor d, rouding up
00015     */
00016     
00017     if (n >= 0)
00018         return ((n + d - 1) / d);
00019     
00020     return ((n - d + 1) / d);
00021     } /*divup*/
00022 
00023 
00024 long divround (long n, long d) {
00025     
00026     /*
00027     divide numerator n by divisor d, rouding as closely as possible
00028     */
00029     
00030     if (n >= 0)
00031         return ((n + d / 2) / d);
00032     
00033     return ((n - d / 2) / d);
00034     } /*divround*/
00035 
00036 
00037 long quantumize (long n, long q) {
00038     
00039     /*
00040     return the lowest multiple of quantum q that is greater (further from 
00041     zero) that n.  useful for quantumizing scroll distances
00042     
00043     9/25/92 dmb: check for zero; it's bogus, but data can be that way
00044     */
00045     
00046     if (q == 0)
00047         return (n);
00048     
00049     return (divup (n, q) * q);
00050     } /*quantumize*/
00051     
00052     
00053 short getsign (long x) {    
00054 
00055     if (x < 0)
00056         return (-1);
00057         
00058     if (x == 0)
00059         return (0);
00060         
00061     return (1);
00062     } /*getsign*/
00063     
00064 
00065 

Generated on Wed May 31 18:19:43 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6