From f029903cd953d24eba57f88e2c8a58a3b9647105 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Fri, 18 Apr 2025 01:04:51 +0300 Subject: Fix '1:angle_between' test failure --- indra/llmath/v3dmath.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v3dmath.h b/indra/llmath/v3dmath.h index e72c150cdc..fcce2c30eb 100644 --- a/indra/llmath/v3dmath.h +++ b/indra/llmath/v3dmath.h @@ -278,21 +278,22 @@ inline const LLVector3d& LLVector3d::setVec(const F64* vec) inline F64 LLVector3d::normVec() { - F64 mag = sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]); + F64 mag = (F32)sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]); // This explicit cast to F32 limits the precision for numerical stability. + // Without it, Unit test "v3dmath_h" fails at "1:angle_between" on macos. F64 oomag; if (mag > FP_MAG_THRESHOLD) { - oomag = 1.f/mag; + oomag = 1.0/mag; mdV[VX] *= oomag; mdV[VY] *= oomag; mdV[VZ] *= oomag; } else { - mdV[VX] = 0.f; - mdV[VY] = 0.f; - mdV[VZ] = 0.f; + mdV[VX] = 0.0; + mdV[VY] = 0.0; + mdV[VZ] = 0.0; mag = 0; } return (mag); @@ -300,21 +301,21 @@ inline F64 LLVector3d::normVec() inline F64 LLVector3d::normalize() { - F64 mag = sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]); + F64 mag = (F32)sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]); // Same as in normVec() above. F64 oomag; if (mag > FP_MAG_THRESHOLD) { - oomag = 1.f/mag; + oomag = 1.0/mag; mdV[VX] *= oomag; mdV[VY] *= oomag; mdV[VZ] *= oomag; } else { - mdV[VX] = 0.f; - mdV[VY] = 0.f; - mdV[VZ] = 0.f; + mdV[VX] = 0.0; + mdV[VY] = 0.0; + mdV[VZ] = 0.0; mag = 0; } return (mag); -- cgit v1.2.3