Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

math_num.h

00001 /*
00002  ************************************************************************
00003  *
00004  *                        Numerical Math Package
00005  *
00006  * The present package implements various algorithms of Numerical Math
00007  *
00008  * $Id: math_num.h,v 1.5 2002/07/17 21:44:56 mary Exp $
00009  *
00010  ************************************************************************
00011  */
00012 
00013 //#ifndef __GNUC__
00014 //#pragma once
00015 //#endif
00016 
00017 #if !defined(MATH_NUM_H)
00018 #define MATH_NUM_H 1
00019 
00020 #ifdef __GNUC__
00021 #if ! defined(TWINE)
00022 //    #pragma interface
00023 #endif
00024 #endif
00025 
00026 #include <float.h>
00027 #include <math.h>
00028 #include "haio.h"
00029 #include "builtin.h"
00030 
00031 
00032 //------------------------------------------------------------------------
00033 //      Assertions, aborts, and related stderr printing
00034 
00035                                 // Print an error message on stderr and
00036                                 // abort, arguments like those of printf()
00037 //void _error(const char * message,...);
00038 
00039                                 // Print a message on stderr
00040                                 // It looks and acts like printf(), only
00041                                 // prints on stderr (which is unbuffered...)
00042 void message(const char * message,...);
00043 
00044 #ifndef assert
00045 #define assert(ex) \
00046         (void)((ex) ? 1 : \
00047               (fprintf(stderr,"Failed assertion " #ex " at line %d of `%s'.\n", \
00048                __LINE__, __FILE__), 0))
00049 #define assertval(ex) assert(ex)
00050 #endif
00051 
00052 #define assure(expr,message)                            \
00053         if      (expr) {;}                              \
00054         else fprintf(stderr,"%s\n at line %d of '%s'.",message,__LINE__, __FILE__)
00055 
00056 /*
00057  *------------------------------------------------------------------------
00058  *                              Some constants
00059  * Compile and run the program epsilon.c to determine the values below for
00060  * your computer
00061  */
00062 
00063 //#define EPSILON               2.22045e-16     // DBL_EPSILON
00064 //#define SQRT_EPSILON  1.49012e-08
00065 
00066 /*
00067  *------------------------------------------------------------------------
00068  *              Brent's minimum and zero finders for 
00069  *                a function of a single argument
00070  */
00071 
00072                         // A function of a single argument
00073 class UnivariateFunctor
00074 {
00075   public:
00076       UnivariateFunctor(); 
00077       virtual ~UnivariateFunctor();
00078       virtual double operator() (const double x);
00079       virtual int junk_func() { return 1; }
00080 };
00081 
00082 
00083                                 // Find a minimum of function f
00084                                 // over the interval [a,b] with the
00085                                 // accuracy tol.
00086                                 // Returns an approx. to the min location
00087 double fminbr(const double a, const double b, 
00088               UnivariateFunctor& f, const double tol=DBL_EPSILON);
00089 
00090 inline int nintf(const double x) { return (fmod(x,1.0) < 0.5) ? (int) x : ((int)x) + 1; } 
00091 
00092 #endif // !defined (MATH_NUM_H)

Generated on Tue Feb 17 02:03:07 2004 for harlem by doxygen 1.3.6