Skip to content

Commit

Permalink
hypot function (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arin-Grigoras committed Aug 18, 2024
1 parent 5b69b50 commit 05c6cb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/header/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ ZPL_DEF zpl_f32 zpl_rsqrt(zpl_f32 a);
ZPL_DEF zpl_f32 zpl_quake_rsqrt(zpl_f32 a); /* NOTE: It's probably better to use 1.0f/zpl_sqrt(a)
* And for simd, there is usually isqrt functions too!
*/
ZPL_DEF zpl_f32 zpl_hypot(zpl_f32 x, zpl_f32 y);
ZPL_DEF zpl_f32 zpl_sin(zpl_f32 radians);
ZPL_DEF zpl_f32 zpl_cos(zpl_f32 radians);
ZPL_DEF zpl_f32 zpl_tan(zpl_f32 radians);
Expand Down
3 changes: 2 additions & 1 deletion code/source/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ zpl_f32 zpl_quake_rsqrt(zpl_f32 a) {
r *= f;
return flipped ? 1.0f / r : r;
}

# else

zpl_f32 zpl_rsqrt(zpl_f32 a) { return 1.0f / __builtin_sqrt(a); }
Expand All @@ -225,6 +224,7 @@ zpl_f32 zpl_quake_rsqrt(zpl_f32 a) {

// TODO: Should this be zpl_exp(y * zpl_log(x)) ???
zpl_f32 zpl_pow(zpl_f32 x, zpl_f32 y) { return __builtin_powf(x, y); }
zpl_f32 zpl_hypot(zpl_f32 x, zpl_f32 y){ return __builtin_sqrt(zpl_square(x) + zpl_square(y)); }

# endif
#else
Expand All @@ -241,6 +241,7 @@ zpl_f32 zpl_quake_rsqrt(zpl_f32 a) {
zpl_f32 zpl_exp(zpl_f32 x) { return expf(x); }
zpl_f32 zpl_log(zpl_f32 x) { return logf(x); }
zpl_f32 zpl_pow(zpl_f32 x, zpl_f32 y) { return powf(x, y); }
zpl_f32 zpl_hypot(zpl_f32 x, zpl_f32 y) { return sqrtf(zpl_square(x) + zpl_square(y)); }
#endif

zpl_f32 zpl_exp2(zpl_f32 x) { return zpl_exp(ZPL_LOG_TWO * x); }
Expand Down

0 comments on commit 05c6cb0

Please sign in to comment.