Debian Codegraph @

libs/CppAddons/CAMath.cpp

raw
1 // Copyright 2003 "Gilles Degottex"
2
3 // This file is part of "CppAddons"
4
5 // "CppAddons" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
9 //
10 // "CppAddons" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19
20 #include "CAMath.h"
21
22
23 const double Math::Pi = 2*acos(0);
24 const double Math::Pi2 = 2*Math::Pi;
25 const float Math::fPi = 2*acos(0);
26
27 const double Math::E = exp(1);
28 const float Math::fE = exp(1);
29
30 double Math::SolOfEq2::getPosSol()
31 {
32 if(x1<0)
33 {
34 if(x2<0)
35 {
36 m_err=NE_X1_AND_X2_NEG;
37 return 0;
38 }
39 else return x2;
40 }
41 else
42 {
43 if(x2>0)
44 {
45 m_err=NE_X1_AND_X2_POS;
46 return 0;
47 }
48 else return x1;
49 }
50 }
51
52 Math::SolOfEq2::SolOfEq2(double a, double b, double c)
53 {
54 m_err = NE_OK;
55
56 if(a==0)
57 {
58 if(b==0)
59 {
60 m_err=NE_A_AND_B_EQ_ZERO;
61 x1=0;
62 x2=0;
63 }
64 else
65 {
66 x1=-c/b;
67 x2=x1;
68 }
69 }
70 else if(b==0)
71 {
72 double d=-c/a;
73 if(d<0)
74 {
75 m_err=NE_RACINE_NEG;
76 x1=0;
77 x2=0;
78 }
79 else
80 {
81 x1=sqrt(d);
82 x2=-x1;
83 }
84 }
85 else
86 {
87 double d=b*b-4*a*c;
88 if(d<0)
89 {
90 m_err=NE_DISCRIMINENT_NEG;
91 x1=0;
92 x2=0;
93 }
94 else
95 {
96 d=sqrt(d);
97
98 a*=2;
99 x1=(-b+d)/a;
100 x2=(-b-d)/a;
101 }
102 }
103 }