Esempio n. 1
0
double MathUtil::power(double left, double right)
{
    if(left == 0 && right == 0)
        throw DomainException("Domain Error: ^: x and y are 0");
    else if(left < 0 && !isInteger(right))
        throw DomainException("Domain Error: ^: base < 0 and exponent is not an integer");

    return pow(left, right);
}
Esempio n. 2
0
//basic functions
double MathUtil::log(double value)
{
    if(value <= 0)
        throw DomainException("Domain Error: log(): argument is 0 or negative");

    return log10(value);
}
Esempio n. 3
0
double MathUtil::atangentInRadians(double value)
{
    if(value < -1 || value > 1)
        throw(DomainException("Domain Error: atan(): argument > 1 or argument < -1"));

    return atan(value);
}
Esempio n. 4
0
double MathUtil::atangentInDegrees(double value)
{
    if(value < -1 || value > 1)
        throw(DomainException("Domain Error: atan(): argument > 1 or argument < -1"));

    return atan(value)*180.0/MathUtil::PI();
}
Esempio n. 5
0
Estimate operator / (const Estimate &lhs, i32 rhs)
{
    if (rhs == 0) throw DomainException("division by int");
    LongFloat r(lhs.m_Value / rhs);

    return Estimate(r, lhs.m_Error / ErrorEstimate(double(rhs)) + RoundingError(r, r.AdditionRoundingError()));
}
Esempio n. 6
0
long long int MathUtil::factorial(double n)
{
    long long int result = 1;

    if(n<0)
        throw DomainException("Domain Error: !: negative operand");
    else if(!isInteger(n))
        throw DomainException("Domain Error: !: non-integer operand");
    else if(n>20)
        throw DomainException("Domain Error: !: operand > 20");

    while(n>1)
    {
        result*=n;
        n--;
    }

    return result;
}
Esempio n. 7
0
void Cosmo::set_up(double OmegaM_val, double OmegaL_val) {
  if (OmegaM_val < 0 || OmegaM_val > 1.0)
    throw BadArgumentException("Cosmo::set_up", "OmegaM_val", "in the range 0.0 <= OmegaM_val <= 1.0");
  if (OmegaL_val < 0 || OmegaL_val > 1.0)
    throw BadArgumentException("Cosmo::set_up", "OmegaL_val", "in the range 0.0 <= OmegaL_val <= 1.0");
  if (std::abs(1.0 - OmegaM_val - OmegaL_val) > std::numeric_limits<double>::epsilon()) 
    throw DomainException("Cosmo::set_up", "OmegaM_val and OmegaL_val must sum to 1.0");
  OmegaM = OmegaM_val;
  OmegaL = OmegaL_val;
}
Esempio n. 8
0
double MathUtil::tangentInRadians(double angle)
{
    double radianResult = 0;
    double radians = angle;

    if(radians > 2*MathUtil::PI() || radians < 0)
        radians = wrapRadians0To2PI(angle);

    if(radians == 0)
        radianResult = 0;
    else if(radians == MathUtil::PI()/2)
        throw DomainException("Domain Error: tan(): argument = PI/2");
    else if(radians == MathUtil::PI())
        radianResult = 0;
    else if(radians == 3*MathUtil::PI()/2)
        throw DomainException("Domain Error: tan(): argument = 3PI/2");
    else if(radians == 2*MathUtil::PI())
        radianResult = 0;
    else
        radianResult = tan(radians);

    return radianResult;
}
Esempio n. 9
0
double MathUtil::tangentInDegrees(double angle)
{
    double degreesResult = 0;
    double degrees = angle;

    if(degrees > 360 || degrees < 0)
        wrapDegrees0To360(angle);

    if(degrees == 0)
        degreesResult = 0;
    else if(degrees == 90)
        throw DomainException("Domain Error: tan(): argument = 90");
    else if(degrees == 180)
        degreesResult = 0;
    else if(degrees == 270)
        throw DomainException("Domain Error: tan(): argument = 270");
    else if(degrees == 360)
        degreesResult = 0;
    else
        degreesResult = tan(degrees*MathUtil::PI()/180.0);

    return degreesResult;
}
Esempio n. 10
0
Estimate Estimate::TruncateNegative(const char *origin) const
{
    if (IsNegative()) throw DomainException(origin);

    if (IsPositive()) return *this;

    // (the theory says
    // we can't always give the correct DomainException, so we shouldn't try)	

    // Get an interval centered at half the upper bound, with the same error.
    LongFloat center((m_Value + m_Error.AsLongFloat()) >> 1);
    Estimate a(center, ErrorEstimate(center));

    assert(!a.IsPositive());

    return a;

    //return a.SetError(a);
}
Esempio n. 11
0
double MathUtil::squareRoot(double value)
{
    if(value < 0)
        throw DomainException("Domain Error: sqrt(): argument is negative");
    return sqrt(value);
}