Fix some code analysis warnings in CalcManager (#1074)

This commit is contained in:
Matt Cooley
2020-03-30 15:23:22 -07:00
committed by GitHub
parent cf735bbcf5
commit f552428d97
30 changed files with 225 additions and 219 deletions

View File

@@ -1063,27 +1063,27 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
// FUNCTION: NumberToString
//
// ARGUMENTS: number representation
// fmt, one of FMT_FLOAT FMT_SCIENTIFIC or
// FMT_ENGINEERING
// fmt, one of NumberFormat::Float, NumberFormat::Scientific or
// NumberFormat::Engineering
// integer radix and int32_t precision value
//
// RETURN: String representation of number.
//
// DESCRIPTION: Converts a number to it's string
// DESCRIPTION: Converts a number to its string
// representation.
//
//-----------------------------------------------------------------------------
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision)
wstring NumberToString(_Inout_ PNUMBER& pnum, NumberFormat format, uint32_t radix, int32_t precision)
{
stripzeroesnum(pnum, precision + 2);
int32_t length = pnum->cdigit;
int32_t exponent = pnum->exp + length; // Actual number of digits to the left of decimal
int32_t oldFormat = format;
if (exponent > precision && format == FMT_FLOAT)
NumberFormat oldFormat = format;
if (exponent > precision && format == NumberFormat::Float)
{
// Force scientific mode to prevent user from assuming 33rd digit is exact.
format = FMT_SCIENTIFIC;
format = NumberFormat::Scientific;
}
// Make length small enough to fit in pret.
@@ -1103,7 +1103,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
divnum(&round, num_two, radix, precision);
// Make round number exponent one below the LSD for the number.
if (exponent > 0 || format == FMT_FLOAT)
if (exponent > 0 || format == NumberFormat::Float)
{
round->exp = pnum->exp + pnum->cdigit - round->cdigit - precision;
}
@@ -1116,7 +1116,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
round->sign = pnum->sign;
}
if (format == FMT_FLOAT)
if (format == NumberFormat::Float)
{
// Figure out if the exponent will fill more space than the non-exponent field.
if ((length - exponent > precision) || (exponent > precision + 3))
@@ -1130,7 +1130,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
{
// Case where too many zeros are to the right or left of the
// decimal pt. And we are forced to switch to scientific form.
format = FMT_SCIENTIFIC;
format = NumberFormat::Scientific;
}
}
else if (length + abs(exponent) < precision && round)
@@ -1163,13 +1163,13 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
int32_t eout = exponent - 1; // Displayed exponent.
MANTTYPE* pmant = pnum->mant + pnum->cdigit - 1;
// Case where too many digits are to the left of the decimal or
// FMT_SCIENTIFIC or FMT_ENGINEERING was specified.
if ((format == FMT_SCIENTIFIC) || (format == FMT_ENGINEERING))
// NumberFormat::Scientific or NumberFormat::Engineering was specified.
if ((format == NumberFormat::Scientific) || (format == NumberFormat::Engineering))
{
useSciForm = true;
if (eout != 0)
{
if (format == FMT_ENGINEERING)
if (format == NumberFormat::Engineering)
{
exponent = (eout % 3);
eout -= exponent;
@@ -1270,7 +1270,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// ARGUMENTS:
// PRAT *representation of a number.
// i32 representation of base to dump to screen.
// fmt, one of FMT_FLOAT FMT_SCIENTIFIC or FMT_ENGINEERING
// fmt, one of NumberFormat::Float, NumberFormat::Scientific, or NumberFormat::Engineering
// precision uint32_t
//
// RETURN: string
@@ -1283,7 +1283,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// why a pointer to the rational is passed in.
//
//-----------------------------------------------------------------------------
wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision)
wstring RatToString(_Inout_ PRAT& prat, NumberFormat format, uint32_t radix, int32_t precision)
{
PNUMBER p = RatToNumber(prat, radix, precision);

View File

@@ -17,17 +17,17 @@
//-----------------------------------------------------------------------------
#include "ratpak.h"
void ascalerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, int32_t precision)
void ascalerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision)
{
switch (angletype)
{
case ANGLE_RAD:
case AngleType::Radians:
break;
case ANGLE_DEG:
case AngleType::Degrees:
divrat(pa, two_pi, precision);
mulrat(pa, rat_360, precision);
break;
case ANGLE_GRAD:
case AngleType::Gradians:
divrat(pa, two_pi, precision);
mulrat(pa, rat_400, precision);
break;
@@ -76,7 +76,7 @@ void _asinrat(PRAT* px, int32_t precision)
DESTROYTAYLOR();
}
void asinanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void asinanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
asinrat(pa, radix, precision);
@@ -164,7 +164,7 @@ void asinrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
//
//-----------------------------------------------------------------------------
void acosanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void acosanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
acosrat(pa, radix, precision);
@@ -249,7 +249,7 @@ void acosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
//
//-----------------------------------------------------------------------------
void atananglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void atananglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
atanrat(pa, radix, precision);

View File

@@ -31,25 +31,20 @@ static constexpr uint32_t BASEX = 0x80000000; // Internal radix used in calculat
typedef uint32_t MANTTYPE;
typedef uint64_t TWO_MANTTYPE;
enum eNUMOBJ_FMT
enum class NumberFormat
{
FMT_FLOAT, // returns floating point, or exponential if number is too big
FMT_SCIENTIFIC, // always returns scientific notation
FMT_ENGINEERING // always returns engineering notation such that exponent is a multiple of 3
Float, // returns floating point, or exponential if number is too big
Scientific, // always returns scientific notation
Engineering // always returns engineering notation such that exponent is a multiple of 3
};
enum eANGLE_TYPE
enum class AngleType
{
ANGLE_DEG, // Calculate trig using 360 degrees per revolution
ANGLE_RAD, // Calculate trig using 2 pi radians per revolution
ANGLE_GRAD // Calculate trig using 400 gradients per revolution
Degrees, // Calculate trig using 360 degrees per revolution
Radians, // Calculate trig using 2 pi radians per revolution
Gradians // Calculate trig using 400 gradians per revolution
};
typedef enum eNUMOBJ_FMT NUMOBJ_FMT;
typedef enum eANGLE_TYPE ANGLE_TYPE;
//-----------------------------------------------------------------------------
//
// NUMBER type is a representation of a generic sized generic radix number
@@ -341,10 +336,10 @@ extern bool equnum(_In_ PNUMBER a, _In_ PNUMBER b); // returns true of a == b
extern bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b); // returns true of a < b
extern bool zernum(_In_ PNUMBER a); // returns true of a == 0
extern bool zerrat(_In_ PRAT a); // returns true if a == 0/q
extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision);
extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, NumberFormat format, uint32_t radix, int32_t precision);
// returns a text representation of a PRAT
extern std::wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision);
extern std::wstring RatToString(_Inout_ PRAT& prat, NumberFormat format, uint32_t radix, int32_t precision);
// converts a PRAT into a PNUMBER
extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision);
// flattens a PRAT by converting it to a PNUMBER and back to a PRAT
@@ -376,7 +371,7 @@ extern PRAT _createrat(void);
// returns a new rat structure with the acos of x->p/x->q taking into account
// angle type
extern void acosanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
extern void acosanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the acosh of x->p/x->q
extern void acoshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
@@ -386,7 +381,7 @@ extern void acosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the asin of x->p/x->q taking into account
// angle type
extern void asinanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
extern void asinanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
extern void asinhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the asinh of x->p/x->q
@@ -396,7 +391,7 @@ extern void asinrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the atan of x->p/x->q taking into account
// angle type
extern void atananglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
extern void atananglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the atanh of x->p/x->q
extern void atanhrat(_Inout_ PRAT* px, int32_t precision);
@@ -412,7 +407,7 @@ extern void cosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the cos of x->p/x->q taking into account
// angle type
extern void cosanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
extern void cosanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the exp of x->p/x->q this should not be called explicitly.
extern void _exprat(_Inout_ PRAT* px, int32_t precision);
@@ -435,14 +430,14 @@ extern void sinrat(_Inout_ PRAT* px);
// returns a new rat structure with the sin of x->p/x->q taking into account
// angle type
extern void sinanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
extern void sinanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
extern void tanhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
extern void tanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the tan of x->p/x->q taking into account
// angle type
extern void tananglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
extern void tananglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
extern void _dupnum(_In_ PNUMBER dest, _In_ const NUMBER* const src);

View File

@@ -16,17 +16,17 @@
#include "ratpak.h"
void scalerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void scalerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
switch (angletype)
{
case ANGLE_RAD:
case AngleType::Radians:
scale2pi(pa, radix, precision);
break;
case ANGLE_DEG:
case AngleType::Degrees:
scale(pa, rat_360, radix, precision);
break;
case ANGLE_GRAD:
case AngleType::Gradians:
scale(pa, rat_400, radix, precision);
break;
}
@@ -98,13 +98,13 @@ void sinrat(PRAT* px, uint32_t radix, int32_t precision)
_sinrat(px, precision);
}
void sinanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void sinanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
scalerat(pa, angletype, radix, precision);
switch (angletype)
{
case ANGLE_DEG:
case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision))
{
subrat(pa, rat_360, precision);
@@ -112,7 +112,7 @@ void sinanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t
divrat(pa, rat_180, precision);
mulrat(pa, pi, precision);
break;
case ANGLE_GRAD:
case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision))
{
subrat(pa, rat_400, precision);
@@ -193,13 +193,13 @@ void cosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
_cosrat(px, radix, precision);
}
void cosanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void cosanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
scalerat(pa, angletype, radix, precision);
switch (angletype)
{
case ANGLE_DEG:
case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision))
{
PRAT ptmp = nullptr;
@@ -211,7 +211,7 @@ void cosanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t
divrat(pa, rat_180, precision);
mulrat(pa, pi, precision);
break;
case ANGLE_GRAD:
case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision))
{
PRAT ptmp = nullptr;
@@ -263,13 +263,13 @@ void tanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
_tanrat(px, radix, precision);
}
void tananglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision)
void tananglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
scalerat(pa, angletype, radix, precision);
switch (angletype)
{
case ANGLE_DEG:
case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision))
{
subrat(pa, rat_180, precision);
@@ -277,7 +277,7 @@ void tananglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t
divrat(pa, rat_180, precision);
mulrat(pa, pi, precision);
break;
case ANGLE_GRAD:
case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision))
{
subrat(pa, rat_200, precision);