Created
April 25, 2016 20:32
-
-
Save mcleary/35a50eb31187be68c59e953ecd4ae9fe 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
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
#include <float.h> | |
#include <math.h> | |
#if 0 | |
// Assossiative operations | |
int main(int argc, char* argv[]) | |
{ | |
float a = 1.0f; | |
float b = 1/pow(2,23); | |
#if 0 | |
float c = (a+b)+b; | |
float d = a+(b+b); | |
#else | |
float c = (a*b)*b; | |
float d = a*(b*b); | |
#endif | |
//printf("FLT_MIN: %100.1000f\n", b); | |
printf("OP1 = %.25f\nOP2 = %.25f \n", c, d); | |
printf("1>1? %d\n1>1? %d\n", c > 1, d > 1); | |
printf("FLT_MIN = %.100f\n", FLT_MIN); | |
printf("FLT_EPSLON = %.25f\n", FLT_EPSILON); | |
printf("1 / 2^24 = %.25f\n", b); | |
return 0; | |
} | |
#endif | |
#if 1 | |
// Machine Precision | |
int main() | |
{ | |
int i = 0; | |
float f = 0; | |
do | |
{ | |
f = 1 + (1 / pow(2, i)); | |
printf("1 + 1/%d = %.10f\n", i, f); | |
i++; | |
} | |
while(f != 1); | |
//printf("%f == %f? %d\n", FLT_MIN, ) | |
return 0; | |
} | |
#endif | |
#if 0 | |
int main() | |
{ | |
float a = FLT_MAX; | |
float b = FLT_MAX / 10000000.0f; | |
float c = FLT_MAX + b; | |
printf("%f\n", FLT_MAX); | |
printf("%f\n", a+b); | |
printf("%f\n", 0.0f/0.0f); | |
return 0; | |
} | |
#endif | |
#if 0 | |
int main() | |
{ | |
float sum = 0; | |
int n = 1; | |
while(n < 1e190) | |
{ | |
sum += 1.0f / n; | |
n++; | |
if(n % 200000 == 0) | |
printf("%d = %f\n", n, sum); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment