How to generate ALL floating numbers?
I'm trying to generate ALL float numbers to a file on C++ (using gcc). My
first attempt was to use FLT_MIN, FLT_MAX & FLT_EPSILON to generate them,
the code was something like this:
#include <cfloat>
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
FILE* handle = freopen("todos_los_float.in","w",stdout);
for(float x = FLT_MIN; x < FLT_MAX; x = x + FLT_EPSILON)
cout << x << endl;
fclose(handle);
return 0;
}
This is not working, as FLT_EPSILON destroys the precision of the number,
for FLT_MIN it takes a huge jump, and it's stop adding much before
reaching FLT_MAX.
I have thought on working and adding on binary form, and just skip the
special meanings (inf, -inf, NaN) but I'm also not sure which is the best
approach for this. How do you suggest to generate the numbers?
No comments:
Post a Comment