From 820f0bf02af475cd7f8e7fb3132a003b61344327 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Sat, 2 May 2015 21:44:26 -0700 Subject: [PATCH] AP_Math: compiler warnings: float to double promotion cast as float because we're in magical template land where T minus T means promote to double --- libraries/AP_Math/AP_Math.h | 1 + libraries/AP_Math/vector3.cpp | 52 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/libraries/AP_Math/AP_Math.h b/libraries/AP_Math/AP_Math.h index c225a9aa68..8d215fd935 100644 --- a/libraries/AP_Math/AP_Math.h +++ b/libraries/AP_Math/AP_Math.h @@ -20,6 +20,7 @@ #include "polygon.h" #include "edc.h" #include "float.h" +#include "AP_Param.h" #ifndef M_PI_F #define M_PI_F 3.141592653589793f diff --git a/libraries/AP_Math/vector3.cpp b/libraries/AP_Math/vector3.cpp index d1759669f4..7e6421304a 100644 --- a/libraries/AP_Math/vector3.cpp +++ b/libraries/AP_Math/vector3.cpp @@ -19,7 +19,7 @@ #include "AP_Math.h" -#define HALF_SQRT_2 0.70710678118654757 +#define HALF_SQRT_2 0.70710678118654757f // rotate a vector by a standard rotation, attempting // to use the minimum number of floating point operations @@ -32,8 +32,8 @@ void Vector3::rotate(enum Rotation rotation) case ROTATION_MAX: return; case ROTATION_YAW_45: { - tmp = HALF_SQRT_2*(x - y); - y = HALF_SQRT_2*(x + y); + tmp = HALF_SQRT_2*(float)(x - y); + y = HALF_SQRT_2*(float)(x + y); x = tmp; return; } @@ -42,8 +42,8 @@ void Vector3::rotate(enum Rotation rotation) return; } case ROTATION_YAW_135: { - tmp = -HALF_SQRT_2*(x + y); - y = HALF_SQRT_2*(x - y); + tmp = -HALF_SQRT_2*(float)(x + y); + y = HALF_SQRT_2*(float)(x - y); x = tmp; return; } @@ -51,8 +51,8 @@ void Vector3::rotate(enum Rotation rotation) x = -x; y = -y; return; case ROTATION_YAW_225: { - tmp = HALF_SQRT_2*(y - x); - y = -HALF_SQRT_2*(x + y); + tmp = HALF_SQRT_2*(float)(y - x); + y = -HALF_SQRT_2*(float)(x + y); x = tmp; return; } @@ -61,8 +61,8 @@ void Vector3::rotate(enum Rotation rotation) return; } case ROTATION_YAW_315: { - tmp = HALF_SQRT_2*(x + y); - y = HALF_SQRT_2*(y - x); + tmp = HALF_SQRT_2*(float)(x + y); + y = HALF_SQRT_2*(float)(y - x); x = tmp; return; } @@ -71,8 +71,8 @@ void Vector3::rotate(enum Rotation rotation) return; } case ROTATION_ROLL_180_YAW_45: { - tmp = HALF_SQRT_2*(x + y); - y = HALF_SQRT_2*(x - y); + tmp = HALF_SQRT_2*(float)(x + y); + y = HALF_SQRT_2*(float)(x - y); x = tmp; z = -z; return; } @@ -81,8 +81,8 @@ void Vector3::rotate(enum Rotation rotation) return; } case ROTATION_ROLL_180_YAW_135: { - tmp = HALF_SQRT_2*(y - x); - y = HALF_SQRT_2*(y + x); + tmp = HALF_SQRT_2*(float)(y - x); + y = HALF_SQRT_2*(float)(y + x); x = tmp; z = -z; return; } @@ -91,8 +91,8 @@ void Vector3::rotate(enum Rotation rotation) return; } case ROTATION_ROLL_180_YAW_225: { - tmp = -HALF_SQRT_2*(x + y); - y = HALF_SQRT_2*(y - x); + tmp = -HALF_SQRT_2*(float)(x + y); + y = HALF_SQRT_2*(float)(y - x); x = tmp; z = -z; return; } @@ -101,8 +101,8 @@ void Vector3::rotate(enum Rotation rotation) return; } case ROTATION_ROLL_180_YAW_315: { - tmp = HALF_SQRT_2*(x - y); - y = -HALF_SQRT_2*(x + y); + tmp = HALF_SQRT_2*(float)(x - y); + y = -HALF_SQRT_2*(float)(x + y); x = tmp; z = -z; return; } @@ -112,8 +112,8 @@ void Vector3::rotate(enum Rotation rotation) } case ROTATION_ROLL_90_YAW_45: { tmp = z; z = y; y = -tmp; - tmp = HALF_SQRT_2*(x - y); - y = HALF_SQRT_2*(x + y); + tmp = HALF_SQRT_2*(float)(x - y); + y = HALF_SQRT_2*(float)(x + y); x = tmp; return; } @@ -124,8 +124,8 @@ void Vector3::rotate(enum Rotation rotation) } case ROTATION_ROLL_90_YAW_135: { tmp = z; z = y; y = -tmp; - tmp = -HALF_SQRT_2*(x + y); - y = HALF_SQRT_2*(x - y); + tmp = -HALF_SQRT_2*(float)(x + y); + y = HALF_SQRT_2*(float)(x - y); x = tmp; return; } @@ -135,8 +135,8 @@ void Vector3::rotate(enum Rotation rotation) } case ROTATION_ROLL_270_YAW_45: { tmp = z; z = -y; y = tmp; - tmp = HALF_SQRT_2*(x - y); - y = HALF_SQRT_2*(x + y); + tmp = HALF_SQRT_2*(float)(x - y); + y = HALF_SQRT_2*(float)(x + y); x = tmp; return; } @@ -147,8 +147,8 @@ void Vector3::rotate(enum Rotation rotation) } case ROTATION_ROLL_270_YAW_135: { tmp = z; z = -y; y = tmp; - tmp = -HALF_SQRT_2*(x + y); - y = HALF_SQRT_2*(x - y); + tmp = -HALF_SQRT_2*(float)(x + y); + y = HALF_SQRT_2*(float)(x - y); x = tmp; return; } @@ -339,7 +339,7 @@ bool Vector3::operator !=(const Vector3 &v) const template float Vector3::angle(const Vector3 &v2) const { - return acosf(((*this)*v2) / (this->length()*v2.length())); + return acosf((*this)*v2) / (float)((this->length()*v2.length())); } // multiplication of transpose by a vector