Skip to content

Instantly share code, notes, and snippets.

@LaurieWired
Created August 12, 2025 16:33
Show Gist options
  • Select an option

  • Save LaurieWired/3f8be4648b3e627e3fcd5607d83b405f to your computer and use it in GitHub Desktop.

Select an option

Save LaurieWired/3f8be4648b3e627e3fcd5607d83b405f to your computer and use it in GitHub Desktop.
//gcc float_code.c -o float_code
//gcc float_code.c -o float_code -ffast-math
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
void print_float_type(float f) {
switch (fpclassify(f)) {
case FP_NORMAL: printf(" (Normal)\n"); break;
case FP_SUBNORMAL: printf(" (Subnormal)\n"); break;
case FP_ZERO: printf(" (Zero)\n"); break;
default: printf(" (Other)\n"); break;
}
}
int main(int argc, char *argv[]) {
float normal = 6.28;
printf("%.4f\n", normal);
printf("%.8f\n", normal);
float subnormal = 0.000000000000000000000000000000000000000000628;
print_float_type(subnormal);
printf("%.50f\n", subnormal);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment