Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

mmath.h

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003     copyright            : (C) 2000 by Marko Grönroos
00004     email                : magi@iki.fi
00005  ***************************************************************************
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************
00013  *
00014  **/
00015 
00016 #ifndef __MATH_HPP__
00017 #define __MATH_HPP__
00018 
00019 #include <magic/mobject.h>
00020 #include <magic/mpackarray.h>
00021 
00022 // In SunOS/Solaris there is a fp-exception class in math.h.... SHINY BLOODY IDIOTS!
00023 //#ifdef __P
00024 //#undef __P
00025 //#endif
00026 //#ifdef SunOS
00027 //#define exception exception_kludge
00028 //#include <math.h>
00029 //#undef exception
00030 //#else
00031 #include <math.h>
00032 //#endif
00033 
00034 BEGIN_NAMESPACE (MagiC);
00035 
00036 
00039 int     rnd         (int range);
00040 
00043 double  frnd        ();
00044 
00048 double  gaussrnd    (double stdv);
00049 
00052 inline double   sqr (double x) {return x*x;}
00053 
00054 //double quadatan (double y, double x);
00055 
00056 template <class T>
00057 inline T sqr (T x) {
00058     return x*x;
00059 }
00060 
00063 inline double sigmoid (double x) {return 1/(1+exp(-x));}
00064 
00065 // |x|
00066 //inline double abs (double a) {
00067 //  return a>=0? a:-a;
00068 //}
00069 
00072 inline void swap (double& x, double& y) {double tmp=x; x=y; y=tmp;}
00073 
00074 #define UNDEFINED_FLOAT 1.2345E30
00075 
00078 inline bool is_undef (double x) {
00079     return x>=1.2345E29;
00080 }
00081 
00085 typedef PackArray<double>   Vector;
00086 
00088 double  sum         (const Vector& x);
00090 double  min         (const Vector& x);
00092 int     minIndex    (const Vector& x);
00094 double  max         (const Vector& x);
00096 int     maxIndex    (const Vector& x);
00098 double  avg         (const Vector& x);
00100 double  stddev      (const Vector& x);
00102 double  stdmerr     (const Vector& x);
00103 
00107 Vector  histogram   (const Vector& x, int n);
00108 
00110 void    add (Vector& x, double m);
00111 
00114 void    multiply (Vector& x, double m);
00115 
00118 void    multiplyToUnity (Vector& x);
00119 
00124 #ifndef ROUND_DOUBLE_THRESHOLD
00125 #define ROUND_DOUBLE_THRESHOLD 1e-15
00126 #endif
00127 
00128 inline bool isRoundZero (double x) {
00129     return fabs(x) < ROUND_DOUBLE_THRESHOLD;
00130 }
00131 
00132 END_NAMESPACE;
00133 
00134 #endif
00135 

Generated on Thu Feb 10 20:06:42 2005 for LibMagiC by doxygen1.2.18