Skip to content

Instantly share code, notes, and snippets.

@jwiegley
Last active August 26, 2022 05:55
Show Gist options
  • Save jwiegley/f8eab8aca4ab60230ecfde0ca62bbf1d to your computer and use it in GitHub Desktop.
Save jwiegley/f8eab8aca4ab60230ecfde0ca62bbf1d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#define BUG_ON_GCC
#ifdef BUG_ON_GCC
__attribute__((noinline))
#else
inline __attribute__((always_inline))
#endif
double safe_pow(
double x,
double y)
{
printf("x = %llx\n", *((unsigned long long *)&x));
printf("y = %llx\n", *((unsigned long long *)&y));
double result = pow(x, y);
printf("r = %llx\n", *((unsigned long long *)&result));
return result;
}
int main() {
printf("%ld\n", sizeof(pow(15.034465284692086, 3.466120406090667)));
printf("%.24f\n", pow(15.034465284692086, 3.466120406090667));
printf("%ld\n", sizeof(safe_pow(15.034465284692086, 3.466120406090667)));
printf("%.24f\n", safe_pow(15.034465284692086, 3.466120406090667));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment