Skip to content

Instantly share code, notes, and snippets.

@coralmw
Created October 3, 2016 09:31
Show Gist options
  • Save coralmw/ddfba51983200cd339c0250179b2b019 to your computer and use it in GitHub Desktop.
Save coralmw/ddfba51983200cd339c0250179b2b019 to your computer and use it in GitHub Desktop.
#include <cfloat>
#include <cmath>
#include <cstdint>
#include <iostream>
int main(void){
float f;
uint64_t correct = 0;
uint64_t tried = 0;
for (f=0.0f; f<INFINITY; f = nextafterf(f, INFINITY)) {
tried++;
if (log(exp(f)) == f) correct++;
if (tried % 10000 == 0) std::cout << std::string(20,'\b') << (double)tried/pow(2, 31);
}
std::cout << "\ncorrect: " << (double)correct/(double)tried * 100.0 << "%" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment