From 48a97dec38e2aeb29fdf176c0dbe6c288bbf5a3d Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sat, 27 Apr 2024 02:26:20 +0300 Subject: [PATCH] Fix warnings in fix library Fix most of "narrowing conversion" warnings. --- fix/fix.cpp | 25 ++++++++++++------------- fix/fix.h | 16 +++++++--------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/fix/fix.cpp b/fix/fix.cpp index 693b7f48..d77dea4e 100644 --- a/fix/fix.cpp +++ b/fix/fix.cpp @@ -64,18 +64,17 @@ * $NoKeywords: $ */ -#include "fix.h" +#include +#include -#include -#include +#include "fix.h" #include "psrand.h" + // Tables for trig functions float sincos_table[321]; // 256 entries + 64 sin-only + 1 for interpolation angle asin_table[257]; // 1 quadrants worth, +1 for interpolation angle acos_table[257]; -#define PI 3.141592654 - // Generate the data for the trig tables void InitMathTables() { int i; @@ -83,13 +82,13 @@ void InitMathTables() { for (i = 0; i < 321; i++) { rad = (float)((double)i / 256.0 * 2 * PI); - sincos_table[i] = (float)sin(rad); + sincos_table[i] = std::sin(rad); } for (i = 0; i < 256; i++) { - s = asin((float)i / 256.0); - c = acos((float)i / 256.0); + s = std::asin((float)i / 256.0f); + c = std::acos((float)i / 256.0f); s = (s / (PI * 2)); c = (c / (PI * 2)); @@ -102,7 +101,7 @@ void InitMathTables() { acos_table[256] = acos_table[255]; // Initialize a random seed. - ps_srand(time(NULL)); + ps_srand(time(nullptr)); } // Returns the sine of the given angle. Linearly interpolates between two entries in a 256-entry table @@ -179,7 +178,7 @@ angle FixAsin(float v) { fix vv; int i, f, aa; - vv = FloatToFix(fabs(v)); + vv = FloatToFix(std::fabs(v)); if (vv >= F1_0) // check for out of range return 0x4000; @@ -201,7 +200,7 @@ angle FixAcos(float v) { fix vv; int i, f, aa; - vv = FloatToFix(fabs(v)); + vv = FloatToFix(std::fabs(v)); if (vv >= F1_0) // check for out of range return 0; @@ -231,12 +230,12 @@ angle FixAtan2(float cos, float sin) { q = (sin * sin) + (cos * cos); - m = sqrt(q); + m = std::sqrt(q); if (m == 0) return 0; - if (fabs(sin) < fabs(cos)) { + if (std::fabs(sin) < std::fabs(cos)) { // sin is smaller, use arcsin t = FixAsin(sin / m); if (cos < 0) diff --git a/fix/fix.h b/fix/fix.h index c8670835..dca5dffa 100644 --- a/fix/fix.h +++ b/fix/fix.h @@ -62,21 +62,19 @@ #define _FIX_H #include - -// Disable the "possible loss of data" warning -#pragma warning(disable : 4244) +#include // Angles are unsigned shorts -typedef unsigned short angle; +typedef uint16_t angle; // The basic fixed-point type -typedef long fix; +typedef int32_t fix; -#define PI 3.141592654 +#define PI 3.141592654f #define PIOVER2 1.570796327 // DAJ // Constants for converted between fix and float -#define FLOAT_SCALER 65536.0 +#define FLOAT_SCALER 65536.0f #define FIX_SHIFT 16 // 1.0 in fixed-point @@ -105,10 +103,10 @@ fix FloatToFixFast(float num); //??#define FloatToFix(num) Round((num) * FLOAT_SCALER) #define FloatToFix(num) ((fix)((num) * FLOAT_SCALER)) #define IntToFix(num) ((num) << FIX_SHIFT) -#define ShortToFix(num) (((long)(num)) << FIX_SHIFT) +#define ShortToFix(num) (((int32_t)(num)) << FIX_SHIFT) #define FixToFloat(num) (((float)(num)) / FLOAT_SCALER) #define FixToInt(num) ((num) >> FIX_SHIFT) -#define FixToShort(num) ((short)((num) >> FIX_SHIFT)) +#define FixToShort(num) ((int16_t)((num) >> FIX_SHIFT)) // use this instead of: // for: (int)floor(x+0.5f) use FloatRound(x)