Skip to content
Open
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
10 changes: 8 additions & 2 deletions src/CalcManager/Ratpack/fact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
PRAT sum = nullptr;
PRAT err = nullptr;
PRAT mpy = nullptr;

PRAT ratRadix = nullptr;

// Set up constants and initial conditions
PRAT ratprec = i32torat(precision);

Expand Down Expand Up @@ -97,7 +98,7 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
exprat(&tmp, radix, precision);
mulrat(&term, tmp, precision);
_lograt(&term, precision);
const auto ratRadix = i32torat(radix);
ratRadix = i32torat(radix);
DUPRAT(tmp, ratRadix);
_lograt(&tmp, precision);
_subrat(&term, tmp, precision);
Expand Down Expand Up @@ -182,6 +183,8 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
destroyrat(*pn);
DUPRAT(*pn, sum);
destroyrat(sum);
destroyrat(ratRadix);
destroyrat(mpy);
}

void factrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
Expand All @@ -208,6 +211,9 @@ void factrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
// Check for negative integers and throw an error.
if ((zerrat(frac) || (LOGRATRADIX(frac) <= -precision)) && (SIGN(*px) == -1))
{
destroyrat(neg_rat_one);
destroyrat(frac);
destroyrat(fact);
throw CALC_E_DOMAIN;
}
while (rat_gt(*px, rat_zero, precision) && (LOGRATRADIX(*px) > -precision))
Expand Down