Flow123d
math_fce.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief ???
27  *
28  */
29 
30 #ifndef MATH_H
31 #define MATH_H
32 
33 //! small matrix types
34 typedef double SmallVec1_t[1];
35 typedef double SmallVec2_t[2];
36 typedef double SmallVec3_t[3];
37 typedef double SmallVec4_t[4];
38 
43 
44 
45 //! Numerical helpers
46 #include <float.h>
47 // DBL_MIN approx.= 2.22507e-308, least nonzero double
48 
49 // this should be used when we want to keep first digit nonzero
50 // such number have full double precision, smaller numbers loose precision
51 #define NUM_ZERO DBL_MIN/DBL_EPSILON
52 
53 // each use of ESP(value) indicate that we use some small value
54 // this small value should be relative to the number we want to compare
55 #define EPS(value) (value)
56 
57 // OBSOLETE
58 #define ZERO EPS(1e-12)
59 
60 #define DBL_EQ(i,j) (fabs((i)-(j))<NUM_ZERO)
61 #define DBL_GE(i,j) ((i)>(j)-NUM_ZERO)
62 #define DBL_LE(i,j) ((i)<(j)+NUM_ZERO)
63 #define DBL_GT(i,j) ((i)>(j)+NUM_ZERO)
64 #define DBL_LT(i,j) ((i)<(j)-NUM_ZERO)
65 
66 //! Usefull math macros
67 #define SQUARE(x) ((x) * (x))
68 #define SGN(x) ( ((x)>ZERO)? (1) : ( ((x)<(-ZERO))? (-1) : (0) ) )
69 #define SUBDET2(i,j,k,l) (a[(i)][(k)]*a[(j)][(l)]-a[(i)][(l)]*a[(j)][(k)])
70 #ifndef M_PI
71  #define M_PI 3.14159265358979323846264338327950288f
72 #endif
73 
74 // vector functions
75 double vector_length(double[]);
76 double scalar_product(double[],double[]);
77 void normalize_vector(double[]);
78 void scale_vector(double[],double);
79 
80 void vector_product(double[],double[],double[]);
81 void vector_difference(double[],double[],double[]);
82 // small matrix operations
83 double Det3( SmallMtx3 a);
84 double MatrixInverse(double *a,double *b,int size);
85 void PrintSmallMatrix(double *mtx, int size );
86 #endif
87 //-----------------------------------------------------------------------------
88 // vim: set cindent: