Created
August 12, 2025 16:33
-
-
Save LaurieWired/3f8be4648b3e627e3fcd5607d83b405f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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