Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/core/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ HNumber function_arctan(Function* f, const Function::ArgumentList& args)
return result;
}

HNumber function_arctan2(Function* f, const Function::ArgumentList& args)
{
ENSURE_ARGUMENT_COUNT(2);
HNumber result = HMath::arctan2(args.at(0), args.at(1));
if (Settings::instance()->angleUnit == 'd')
result = HMath::rad2deg(result);
return result;
}

HNumber function_sinh(Function* f, const Function::ArgumentList& args)
{
ENSURE_ARGUMENT_COUNT(1);
Expand Down Expand Up @@ -623,6 +632,12 @@ HNumber function_idiv(Function* f, const Function::ArgumentList& args)
return HMath::idiv(args.at(0), args.at(1));
}

HNumber function_div(Function* f, const Function::ArgumentList& args)
{
ENSURE_ARGUMENT_COUNT(2);
return HMath::idiv(args.at(0), args.at(1));
}

HNumber function_mod(Function* f, const Function::ArgumentList& args)
{
ENSURE_ARGUMENT_COUNT(2);
Expand Down Expand Up @@ -687,6 +702,7 @@ void FunctionRepo::createFunctions()
FUNCTION_INSERT(artanh);
FUNCTION_INSERT(arcsin);
FUNCTION_INSERT(arctan);
FUNCTION_INSERT(arctan2);
FUNCTION_INSERT(cos);
FUNCTION_INSERT(cosh);
FUNCTION_INSERT(cot);
Expand Down Expand Up @@ -714,6 +730,7 @@ void FunctionRepo::createFunctions()
FUNCTION_INSERT(shl);
FUNCTION_INSERT(shr);
FUNCTION_INSERT(idiv);
FUNCTION_INSERT(div);
FUNCTION_INSERT(mod);
}

Expand Down Expand Up @@ -767,6 +784,7 @@ void FunctionRepo::setNonTranslatableFunctionUsages()
FUNCTION_USAGE(artanh, "x");
FUNCTION_USAGE(arcsin, "x");
FUNCTION_USAGE(arctan, "x");
FUNCTION_USAGE(arctan2, "y; x");
FUNCTION_USAGE(average, "x<sub>1</sub>; x<sub>2</sub>; ...");
FUNCTION_USAGE(bin, "n");
FUNCTION_USAGE(cbrt, "x");
Expand Down Expand Up @@ -822,6 +840,7 @@ void FunctionRepo::setTranslatableFunctionUsages()
FUNCTION_USAGE_TR(binommean, tr("trials; probability"));
FUNCTION_USAGE_TR(binompmf, tr("hits; trials; probability"));
FUNCTION_USAGE_TR(binomvar, tr("trials; probability"));
FUNCTION_USAGE_TR(div, tr("dividend; divisor"));
FUNCTION_USAGE_TR(hypercdf, tr("max; total; hits; trials"));
FUNCTION_USAGE_TR(hypermean, tr("total; hits; trials"));
FUNCTION_USAGE_TR(hyperpmf, tr("count; total; hits; trials"));
Expand Down Expand Up @@ -850,6 +869,7 @@ void FunctionRepo::setFunctionNames()
FUNCTION_NAME(artanh, tr("Area Hyperbolic Tangent"));
FUNCTION_NAME(arcsin, tr("Arc Sine"));
FUNCTION_NAME(arctan, tr("Arc Tangent"));
FUNCTION_NAME(arctan2, tr("Arc Tangent from Cathedus"));
FUNCTION_NAME(average, tr("Average (Arithmetic Mean)"));
FUNCTION_NAME(bin, tr("Binary Representation"));
FUNCTION_NAME(binomcdf, tr("Binomial Cumulative Distribution Function"));
Expand All @@ -864,6 +884,7 @@ void FunctionRepo::setFunctionNames()
FUNCTION_NAME(csc, tr("Cosecant"));
FUNCTION_NAME(dec, tr("Decimal Representation"));
FUNCTION_NAME(degrees, tr("Degrees of Arc"));
FUNCTION_NAME(div, tr("Integer Quotient"));
FUNCTION_NAME(erf, tr("Error Function"));
FUNCTION_NAME(erfc, tr("Complementary Error Function"));
FUNCTION_NAME(exp, tr("Exponential"));
Expand Down
15 changes: 15 additions & 0 deletions src/math/floathmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ float_arctan(
return 1;
}

char
float_arctan2(
floatnum x,
floatnum y,
int digits)
{
if (!chckmathparam(x, digits))
return 0;
if (!chckmathparam(y, digits))
return 0;
float_div(x, x, y, digits);
_arctan(x, digits);
return 1;
}

char
float_arcsin(
floatnum x,
Expand Down
6 changes: 6 additions & 0 deletions src/math/floathmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ char float_power10(floatnum x, int digits);
InvalidPrecision (digits > MATHPRECISION) */
char float_arctan(floatnum x, int digits);

/* evaluates arctan of arguments, resulting in a full circle
-pi<x<= pi range.
Errors: NaNOperand
InvalidPrecision (digits > MATHPRECISION) */
char float_arctan2(floatnum y, floatnum x, int digits);

/* evaluates arcsin x for -1 <= x <= 1, yielding a result
-pi/2 <= result <= pi/2.
In case of an error, x is set to NaN and 0 is returned.
Expand Down
2 changes: 1 addition & 1 deletion src/math/floatnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void float_create(floatnum f);
any subsequent arithmetic operation on this variable will fail.
However, a variable such finalized can still be re-used without prior
initialization, by making it the destination of an operation.
If you wish to deliberately "empty" a variable, without detroying it,
If you wish to deliberately "empty" a variable, without destroying it,
call this function.
An alias "float_free" to this function is defined that you
may use anywhere as a replacement for float_setnan.
Expand Down
26 changes: 26 additions & 0 deletions src/math/hmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,32 @@ HNumber HMath::arctan( const HNumber & x )
return result;
};

/**
* Returns the arc tangent calculated from the two cathedus.
* It's calculated from (opposite leg / adjacent leg) and
* results in a full circle range (-Pi;Pi) depending on
* the sign of the respective legs.
* Both legs can not be 0 the same time.
*/
HNumber HMath::arctan2( const HNumber & x, const HNumber & y )
{
/* x: opposite leg; y: adjacent leg */
Error error = checkNaNParam(*x.d, y.d);
if (error != Success)
return HMath::nan(error);

if (x.isZero() && y.isZero()) return HMath::nan();
if (x.isPositive() && y.isZero()) return (HMath::pi()/2.0);
if (x.isNegative() && y.isZero()) return (0.0-(HMath::pi()/2.0));

HNumber offset = HNumber(0.0);
/* 2. Quadrant */
if (x.isPositive() && y.isNegative()) offset+=HMath::pi();
/* 3. Quadrant */
if (x.isNegative() && y.isNegative()) offset-=HMath::pi();
return (arctan(x/y)+offset);
}

/**
* Returns the arc sine of x.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/math/hmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class HMath
static HNumber arcsin( const HNumber & x );
static HNumber arccos( const HNumber & x );
static HNumber arctan( const HNumber & x );
static HNumber arctan2( const HNumber & x, const HNumber & y );
// HIGHER MATH FUNCTIONS
static HNumber factorial( const HNumber & x, const HNumber & base = HNumber(1) );
static HNumber gamma( const HNumber & x);
Expand Down Expand Up @@ -173,4 +174,4 @@ class HMath

std::ostream & operator<<( std::ostream &, const HNumber & );

#endif
#endif