Fix warnings in fix library

Fix most of "narrowing conversion" warnings.
This commit is contained in:
Azamat H. Hackimov
2024-04-27 02:26:20 +03:00
committed by Jeod
parent 536b83d10f
commit 48a97dec38
2 changed files with 19 additions and 22 deletions

View File

@@ -64,18 +64,17 @@
* $NoKeywords: $
*/
#include "fix.h"
#include <cmath>
#include <ctime>
#include <time.h>
#include <stdlib.h>
#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)

View File

@@ -62,21 +62,19 @@
#define _FIX_H
#include <cmath>
// Disable the "possible loss of data" warning
#pragma warning(disable : 4244)
#include <cstdint>
// 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)