⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e.cpp

📁 一个非常有用的开源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
typedef REAL abl_mat2[6][2];     /* in spliwert ......................*/
/*.IX{abl\unt mat2}*/

typedef REAL mat4x4[4][4];       /* type for bicubic splines          */

/*--------------------------------------------------------------------*
 * Type declarations by Albert Becker                                 *
 *--------------------------------------------------------------------*/

 /* Real functions ...................................................*/
 typedef REAL (* REALFCT)  (REAL);
/*.IX{REALFCT}*/

 /* Real multi-dimensional functions .................................*/
 typedef int (* FNFCT)  (int, REAL [], REAL []);
/*.IX{FNFCT}*/

 /* Functions for finding the Jacobi matrix ..........................*/
 typedef int (* JACOFCT)  (int, REAL [], REAL * []);
/*.IX{JACOFCT}*/



/***********************************************************************
* define sevaral important macros                                      *
* NOTE:    Borland C++ offers floating point standard functions        *
*          suitable for long double type from version 3.0 on such as   *
*          expl() instead of exp(), sinl() instead of sin() etc. But   *
*          Borland C++ 3.0 does not seem to define a macro that lets   *
*          the user differentiate it from  Borland C++ 2.0 and below,  *
*          the user is forced to do so himself: If using Borland C++   *
*          3.0 and long double the user should define the macro BC3    *
*          before compiling. Only in this case will the new maximally  *
*          precise floating point functions be used.                   *
***********************************************************************/

#define BASIS     2               /* Basis of number representation   */
/*.IX{BASIS}*/
#define EPSROOT   epsroot()       /* square root of MACH_EPS          */
/*.IX{EPSROOT}*/
#define EPSQUAD   epsquad()       /* square of MACH_EPS               */
/*.IX{EPSQUAD}*/
#define MAXROOT   maxroot()       /* square root of the largest       */
/*.IX{MAXROOT}*/
                                  /* floating point number            */
#ifndef PI
#define PI        pi()            /* pi = 3.14...                     */
/*.IX{PI}*/
#endif
#define EXP_1     exp_1()         /* e = 2.71...                      */
/*.IX{EXP\unt 1}*/

#define ZERO      (REAL)0.0       /* declare names for recurring      */
/*.IX{ZERO}*/
#define ONE       (REAL)1.0       /* floating point numbers           */
/*.IX{ONE}*/
#define TWO       (REAL)2.0
/*.IX{TWO}*/
#define THREE     (REAL)3.0
/*.IX{THREE}*/
#define FOUR      (REAL)4.0
/*.IX{FOUR}*/
#define FIVE      (REAL)5.0
/*.IX{FIVE}*/
#define SIX       (REAL)6.0
/*.IX{SIX}*/
#define EIGHT     (REAL)8.0
/*.IX{EIGHT}*/
#define NINE      (REAL)9.0
/*.IX{NINE}*/
#define TEN       (REAL)10.0
/*.IX{TEN}*/
#define HALF      (REAL)0.5
/*.IX{HALF}*/

#ifdef __BORLANDC__
#if __BORLANDC__ >= 0x0400          /* a BC distinguishable from BC2  */
                                    /* and with long double functions */
                                    /* (at least Borland C++ 3.1 or   */
                                    /* Borland C++ 1.00 for OS/2)?    */
#define BC3                         /* define `BC3' automatically     */
#endif
#endif

#ifdef _MSC_VER
#if _MSC_VER     >= 0x0258          /* a MC distinguishable from QC2  */
                                    /* and with long double functions */
                                    /* (at least Microsoft C 6.00A)?  */
#define MC6                         /* define MC6 automatically       */
#endif
#endif

#if defined(LDOUBLE) &&                     /* Borland C++ 3.0 or    */\
    (defined(BC3) || defined(MC6) ||        /* Microsoft C 6.0 or    */\
     defined(EMX09B))                       /* emx 0.9b (GCC272) with */
                                            /* maximal precision?     */
#define FABS(x)    fabsl((x))               /* use the long double    */
/*.IX{FABS}*/
#define SQRT(x)    sqrtl((x))               /* versions of the basic  */
/*.IX{SQRT}*/
#define POW(x, y)  powl((x), (y))           /* floating point         */
/*.IX{POW}*/
#define SIN(x)     sinl((x))                /* functions              */
/*.IX{SIN}*/
#define COS(x)     cosl((x))
/*.IX{COS}*/
#define EXP(x)     expl((x))
/*.IX{EXP}*/
#define LOG(x)     logl((x))
/*.IX{LOG}*/
#define ATAN(x)    atanl((x))
/*.IX{ATAN}*/
#define ACOS(x)    acosl((x))
/*.IX{ACOS}*/
#define COSH(x)    coshl((x))
/*.IX{COSH}*/

#else                                       /* less precision or not a*/
                                            /* BC3 and not a MC6 ?    */
#define FABS(x)    (REAL)fabs((double)(x))  /* declare names of basic */
#ifdef LONG_DOUBLE_USED                     /* floating point         */
#define SQRT(x)    sqrtlong((x))            /* functions that can be  */
/*.IX{SQRT}*/
#else                                       /* used in each of the    */
#define SQRT(x)    (REAL)sqrt((double)(x))  /* three precisions       */
#endif
#define POW(x, y)  (REAL)pow((double)(x), \
/*.IX{POW}*/                              \
                             (double)(y))
#define SIN(x)     (REAL)sin((double)(x))
/*.IX{SIN}*/
#define COS(x)     (REAL)cos((double)(x))
/*.IX{COS}*/
#define EXP(x)     (REAL)exp((double)(x))
/*.IX{EXP}*/
#define LOG(x)     (REAL)log((double)(x))
/*.IX{LOG}*/
#define ATAN(x)    (REAL)atan((double)(x))
/*.IX{ATAN}*/
#define ACOS(x)    (REAL)acos((double)(x))
/*.IX{ACOS}*/
#define COSH(x)    (REAL)cosh((double)(x))
/*.IX{COSH}*/
#endif

#undef sign
#undef min
#undef max
#define sign(x, y) (((y) < ZERO) ? -FABS(x) :     /* |x| times     */  \
/*.IX{sign}*/                                                          \
                                    FABS(x))      /* sign of y     */
#define min(a, b)        (((a) < (b)) ? (a) : (b))
/*.IX{min}*/
#define max(a, b)        (((a) > (b)) ? (a) : (b))
/*.IX{max}*/
#define SWAP(typ, a, b)                    /* swap two objects of   */ \
/*.IX{SWAP}*/                                                          \
  { typ temp; temp = a; a = b; b = temp; } /* arbitrary type        */

/* ------------------ Macros by Albert Becker ----------------------- */
#ifndef ABS
#define ABS(X) (((X) >= ZERO) ? (X) : -(X))    /* Absolute value of X */
#endif // !ABS
/*.IX{ABS}*/
#define SIGN(X,Y) \
/*.IX{SIGN}*/     \
             (((Y) < ZERO) ? -ABS(X) : ABS(X))    /* sign of Y times  */
                                                  /* ABS(X)           */
#define SQR(X) ((X) * (X))                     /* square of X         */
/*.IX{SQR}*/

#define FORMAT_IN      "%lg"               /* Input format for  REAL  */
/*.IX{FORMAT\unt IN}*/
#define FORMAT_LF      "% "LZP"f "         /* Format l for  REAL      */
/*.IX{FORMAT\unt LF}*/
#define FORMAT_126LF   "% 12.6"LZP"f "     /* Format 12.6f for  REAL  */
/*.IX{FORMAT\unt 126LF}*/
#define FORMAT_2010LF  "% 20.10"LZP"f "    /* Format 20.10f for  REAL */
/*.IX{FORMAT\unt 2010LF}*/
#define FORMAT_2016LF  "% 20.16"LZP"f "    /* Format 20.16f for REAL  */
/*.IX{FORMAT\unt 2016LF}*/
#define FORMAT_LE      "% "LZP"e "         /* Format e for REAL       */
/*.IX{FORMAT\unt LE}*/
#define FORMAT_2016LE  "% 20.16"LZP"e "    /* Format 20.16e for REAL  */
/*.IX{FORMAT\unt 2016LE}*/



/***********************************************************************
* declare all external functions defined in basis.c                    *
***********************************************************************/

int basis(void);             /* find basis for number representation  */

REAL mach_eps(void);         /* find machine constant                 */

REAL epsroot(void);          /* find square root of machine constant  */

REAL epsquad(void);          /* find square of machine constant       */

REAL maxroot(void);   /* Root of the largest representable number ....*/

REAL posmin(void);           /* find smallst positive floating point  */
                             /* number                                */

REAL pi(void);               /* find  pi                              */

REAL exp_1(void);            /* find e                                */

REAL sqr(REAL x);            /* square a floating point number        */

void fehler_melden   /* Write error messages to stdout and stderr ....*/
                  (
                   char text[],          /* error description ........*/
                   int  fehlernummer,    /* Number of error ..........*/
                   char dateiname[],     /* file with error  .........*/
                   int  zeilennummer     /* file name, row number ....*/
                  );

int umleiten            /* Perhaps redirect stdin or stdout to a file */
            (
             int argc,       /* number of arguments in command line ..*/
             char *argv[]    /* Vector of arguments ..................*/
            );               /* error code ...........................*/

void readln(void);             /* Skip the remainder of line in stdin */

void getline          /* Read one line from stdin ....................*/
            (
             char kette[],    /* Vector with the read text ...........*/
             int limit        /* maximal length of kette .............*/
            );

int intervall    /* Find the number for a value inside a partition ...*/
             (
              int n,         /* lenght of partition ..................*/
              REAL xwert,    /* number whose interval index is wanted */
              REAL x[]       /* partition ............................*/
             );              /* Index for xwert ......................*/

REAL horner        /* Horner scheme for polynomial evaluations .......*/
           (
            int n,                         /* Polynomial degree ......*/
            REAL a[],                      /* Polynomial coefficients */
            REAL x                         /* place of evaluation ....*/
           );                              /* Polynomial value at x ..*/

REAL norm_max      /* Find the maximum norm of a REAL vector .........*/
             (
              REAL vektor[],               /* vector .................*/
              int  n                       /* length of vector .......*/
             );                            /* Maximum norm ...........*/

REAL skalprod           /* standard scalar product of two REAL vectors*/
        (
         REAL v[],                 /* 1st vector .....................*/
         REAL w[],                 /* 2nd vector .....................*/
         int  n                    /* vector length...................*/
        );                         /* scalar product .................*/

void copy_vector        /* copy a REAL vector ........................*/
                (
                 REAL ziel[],            /* copied vector ............*/
                 REAL quelle[],          /* original vector ..........*/
                 int  n                  /* length of vector .........*/
                );


/*--------------------------------------------------------------------*
 * Basic functions chapter 1 (by Albert Becker) ......................*
 *--------------------------------------------------------------------*/

long double sqrtlong  (long double x);

int comdiv              /* Complex division ..........................*/
           (
            REAL   ar,            /* Real part of numerator ..........*/
            REAL   ai,            /* Imaginary part of numerator .....*/
            REAL   br,            /* Real part of denominator ........*/
            REAL   bi,            /* Imaginary part of denominator ...*/
            REAL * cr,            /* Real part of quotient ...........*/
            REAL * ci             /* Imaginary part of quotient ......*/
           );

REAL comabs             /* Complex absolute value ....................*/
              (
               REAL  ar,          /* Real part .......................*/
               REAL  ai           /* Imaginary part ..................*/
              );

void quadsolv           /* Complex quadratic equation ................*/
             (
               REAL    ar,        /* second degree coefficient .......*/
               REAL    ai,
               REAL    br,        /* linear coefficient ..............*/
               REAL    bi,
               REAL    cr,        /* polynomial constant .............*/
               REAL    ci,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -