X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmisc.h;h=a1be9f9f236e77902f12079ac610b617f570ebed;hb=d7b5d9144738a5a8989d45a01f4e458a78b68c0b;hp=d8d197022e0453382cf84f4554c868f453729400;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/misc.h b/src/misc.h index d8d197022e..a1be9f9f23 100644 --- a/src/misc.h +++ b/src/misc.h @@ -14,95 +14,82 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #if !math_misc_h #define math_misc_h 1 +#include #include +#define EPSILON (10 * DBL_EPSILON) + /* HUGE_VAL is traditionally defined as positive infinity, or alternatively, DBL_MAX. */ #if !HAVE_ISINF -#define isinf(X) \ - (fabs (X) == HUGE_VAL) +#define isinf(X) (fabs (X) == HUGE_VAL) #endif /* A Not a Number is not equal to itself. */ #if !HAVE_ISNAN -#define isnan(X) \ - ((X) != (X)) +#define isnan(X) ((X) != (X)) #endif /* Finite numbers are not infinities or NaNs. */ #if !HAVE_FINITE -#define finite(X) \ - (!isinf (X) && !isnan (X)) +#define finite(X) (!isinf (X) && !isnan (X)) #elif HAVE_IEEEFP_H #include /* Declares finite() under Solaris. */ #endif -#if __TURBOC__ -#include /* screwed-up Borland headers define min(), max(), - so we might as well let 'em */ -#endif - #ifndef min -#if __GNUC__ && !__STRICT_ANSI__ -#define min(A, B) \ - ({ \ - int _a = (A), _b = (B); \ - _a < _b ? _a : _b; \ - }) -#else /* !__GNUC__ */ -#define min(A, B) \ - ((A) < (B) ? (A) : (B)) -#endif /* !__GNUC__ */ -#endif /* !min */ +#define min(A, B) ((A) < (B) ? (A) : (B)) +#endif #ifndef max -#if __GNUC__ && !__STRICT_ANSI__ -#define max(A, B) \ - ({ \ - int _a = (A), _b = (B); \ - _a > _b ? _a : _b; \ - }) -#else /* !__GNUC__ */ -#define max(A, B) \ - ((A) > (B) ? (A) : (B)) -#endif /* !__GNUC__ */ -#endif /* !max */ +#define max(A, B) ((A) > (B) ? (A) : (B)) +#endif /* Clamps A to be between B and C. */ -#define range(A, B, C) \ - ((A) < (B) ? (B) : ((A) > (C) ? (C) : (A))) +#define range(A, B, C) ((A) < (B) ? (B) : ((A) > (C) ? (C) : (A))) /* Divides nonnegative X by positive Y, rounding up. */ -#define DIV_RND_UP(X, Y) \ - (((X) + ((Y) - 1)) / (Y)) +#define DIV_RND_UP(X, Y) (((X) + ((Y) - 1)) / (Y)) /* Returns nonnegative difference between {nonnegative X} and {the least multiple of positive Y greater than or equal to X}. */ -#if __GNUC__ && !__STRICT_ANSI__ -#define REM_RND_UP(X, Y) \ - ({ \ - int rem = (X) % (Y); \ - rem ? (Y) - rem : 0; \ - }) -#else -#define REM_RND_UP(X, Y) \ - ((X) % (Y) ? (Y) - (X) % (Y) : 0) -#endif +#define REM_RND_UP(X, Y) ((X) % (Y) ? (Y) - (X) % (Y) : 0) /* Rounds X up to the next multiple of Y. */ -#define ROUND_UP(X, Y) \ - (((X) + ((Y) - 1)) / (Y) * (Y)) +#define ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y) * (Y)) /* Rounds X down to the previous multiple of Y. */ -#define ROUND_DOWN(X, Y) \ - ((X) / (Y) * (Y)) +#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y)) int intlog10 (unsigned); +/* Returns the square of X. */ +static inline double +pow2 (double x) +{ + return x * x; +} + +/* Returns the cube of X. */ +static inline double +pow3 (double x) +{ + return x * x * x; +} + +/* Returns the fourth power of X. */ +static inline double +pow4 (double x) +{ + double y = x * x; + y *= y; + return y; +} + #endif /* math/misc.h */