Skip to content

Commit 06f0c63

Browse files
committed
Merge pull request #104273 from Ivorforce/fabs-absf
Simplify and optimize `Math::absf` implementation to use `::fabs` and `::fabsf`.
2 parents 5750d4f + 24c11de commit 06f0c63

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

core/math/math_funcs.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -628,24 +628,11 @@ class Math {
628628
}
629629

630630
static _ALWAYS_INLINE_ float absf(float g) {
631-
union {
632-
float f;
633-
uint32_t i;
634-
} u;
635-
636-
u.f = g;
637-
u.i &= 2147483647u;
638-
return u.f;
631+
return ::fabsf(g);
639632
}
640633

641634
static _ALWAYS_INLINE_ double absd(double g) {
642-
union {
643-
double d;
644-
uint64_t i;
645-
} u;
646-
u.d = g;
647-
u.i &= (uint64_t)9223372036854775807ll;
648-
return u.d;
635+
return ::fabs(g);
649636
}
650637

651638
// This function should be as fast as possible and rounding mode should not matter.

0 commit comments

Comments
 (0)