Skip to content

Commit f029903

Browse files
committed
Fix '1:angle_between' test failure
1 parent c0ecfce commit f029903

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

indra/llmath/v3dmath.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,43 +278,44 @@ inline const LLVector3d& LLVector3d::setVec(const F64* vec)
278278

279279
inline F64 LLVector3d::normVec()
280280
{
281-
F64 mag = sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]);
281+
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.
282+
// Without it, Unit test "v3dmath_h" fails at "1:angle_between" on macos.
282283
F64 oomag;
283284

284285
if (mag > FP_MAG_THRESHOLD)
285286
{
286-
oomag = 1.f/mag;
287+
oomag = 1.0/mag;
287288
mdV[VX] *= oomag;
288289
mdV[VY] *= oomag;
289290
mdV[VZ] *= oomag;
290291
}
291292
else
292293
{
293-
mdV[VX] = 0.f;
294-
mdV[VY] = 0.f;
295-
mdV[VZ] = 0.f;
294+
mdV[VX] = 0.0;
295+
mdV[VY] = 0.0;
296+
mdV[VZ] = 0.0;
296297
mag = 0;
297298
}
298299
return (mag);
299300
}
300301

301302
inline F64 LLVector3d::normalize()
302303
{
303-
F64 mag = sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]);
304+
F64 mag = (F32)sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]); // Same as in normVec() above.
304305
F64 oomag;
305306

306307
if (mag > FP_MAG_THRESHOLD)
307308
{
308-
oomag = 1.f/mag;
309+
oomag = 1.0/mag;
309310
mdV[VX] *= oomag;
310311
mdV[VY] *= oomag;
311312
mdV[VZ] *= oomag;
312313
}
313314
else
314315
{
315-
mdV[VX] = 0.f;
316-
mdV[VY] = 0.f;
317-
mdV[VZ] = 0.f;
316+
mdV[VX] = 0.0;
317+
mdV[VY] = 0.0;
318+
mdV[VZ] = 0.0;
318319
mag = 0;
319320
}
320321
return (mag);

0 commit comments

Comments
 (0)