shithub: qk1

Download patch

ref: 116ac5a454742c6f0b1c1a16a987ffa2c1db012f
parent: 6c2828bf362336de5744f226da19d6049f0a10dd
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Oct 14 18:05:08 EDT 2023

a bit more precision in a few places

--- a/mathlib.c
+++ b/mathlib.c
@@ -124,13 +124,7 @@
 
 float	anglemod(float a)
 {
-	/*
-	if (a >= 0)
-		a -= 360*(int)(a/360);
-	else
-		a += 360*( 1 + (int)(-a/360) );
-	*/
-	a = (360.0/65536) * ((int)(a*(65536/360.0)) & 65535);
+	a = (360.0/65536.0) * ((int)(a*(65536.0/360.0)) & 65535);
 	return a;
 }
 
@@ -257,16 +251,16 @@
 
 void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
 {
-	float		angle;
-	float		sr, sp, sy, cr, cp, cy;
-	
-	angle = angles[YAW] * (M_PI*2 / 360);
+	double		angle;
+	double		sr, sp, sy, cr, cp, cy;
+
+	angle = angles[YAW] * (M_PI*2 / 360.0);
 	sy = sin(angle);
 	cy = cos(angle);
-	angle = angles[PITCH] * (M_PI*2 / 360);
+	angle = angles[PITCH] * (M_PI*2 / 360.0);
 	sp = sin(angle);
 	cp = cos(angle);
-	angle = angles[ROLL] * (M_PI*2 / 360);
+	angle = angles[ROLL] * (M_PI*2 / 360.0);
 	sr = sin(angle);
 	cr = cos(angle);
 
@@ -332,8 +326,6 @@
 	cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
 	cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
 }
-
-double sqrt(double x);
 
 vec_t Length(vec3_t v)
 {
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -390,7 +390,7 @@
 		yaw = 0;
 	else
 	{
-		yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
+		yaw = atan2(value1[1], value1[0]) * 180.0 / M_PI;
 		if (yaw < 0)
 			yaw += 360;
 	}
@@ -409,8 +409,8 @@
 void PF_vectoangles (void)
 {
 	float	*value1;
-	float	forward;
-	float	yaw, pitch;
+	double	forward;
+	double	yaw, pitch;
 	
 	value1 = G_VECTOR(OFS_PARM0);
 
@@ -424,12 +424,12 @@
 	}
 	else
 	{
-		yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
+		yaw = atan2(value1[1], value1[0]) * 180.0 / M_PI;
 		if (yaw < 0)
 			yaw += 360;
 
 		forward = sqrt (value1[0]*value1[0] + value1[1]*value1[1]);
-		pitch = (int) (atan2(value1[2], forward) * 180 / M_PI);
+		pitch = atan2(value1[2], forward) * 180 / M_PI;
 		if (pitch < 0)
 			pitch += 360;
 	}
@@ -1151,10 +1151,7 @@
 {
 	float	f;
 	f = G_FLOAT(OFS_PARM0);
-	if (f > 0)
-		G_FLOAT(OFS_RETURN) = (int)(f + 0.5);
-	else
-		G_FLOAT(OFS_RETURN) = (int)(f - 0.5);
+	G_FLOAT(OFS_RETURN) = Qrint(f);
 }
 void PF_floor (void)
 {