small optimisation to normalisation function

This commit is contained in:
2025-03-10 13:01:38 +01:00
parent 4d30ca3233
commit 223790941c
3 changed files with 6 additions and 6 deletions

View File

@@ -45,8 +45,8 @@ static inline float float2_mag(float2 v) {
// normalizes the float2
static inline float2 float2_norm(float2 v) {
float len = float2_mag(v);
return float2_div(v, len);
float s = 1.0F / float2_mag(v); // get the scaling factor
return float2_scale(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
}
// gets the dot product of two float2s

View File

@@ -46,8 +46,8 @@ static inline float float3_mag(float3 v) {
// normalizes the float3
static inline float3 float3_norm(float3 v) {
float len = float3_mag(v);
return float3_div(v, len);
float s = 1.0F / float3_mag(v); // get the scaling factor
return float3_scale(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
}
// gets the dot product of two float3s

View File

@@ -47,8 +47,8 @@ static inline float float4_mag(float4 v) {
// normalizes the float4
static inline float4 float4_norm(float4 v) {
float len = float4_mag(v);
return float4_div(v, len);
float s = 1.0F / float4_mag(v); // get the scaling factor
return float4_scale(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
}
// gets the dot product of two float4s