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