Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hypot function #118

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading