Skip to content

Instantly share code, notes, and snippets.

@evgeni
Created September 14, 2012 13:26
Show Gist options
  • Save evgeni/3721892 to your computer and use it in GitHub Desktop.
Save evgeni/3721892 to your computer and use it in GitHub Desktop.
/**
* fuck around with stream precisions
* call like this:
* for i in `seq 20`; do echo "precision=$i"; ./foo $i; done
* watch the streamint being properly parsed to 5, or sometimes not
*/
#include <limits>
#include <sstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main( int argc, char **argv ) {
int p = atoi(argv[1]);
double maxdouble = numeric_limits<double>::max();
stringstream stream;
stream.precision(p);
stream << maxdouble << " " << "5" << " ";
cout << stream.str() << endl;
int streamint;
double streamdouble;
stream >> streamdouble >> streamint;
cout << "Double: " << streamdouble << " int: " << streamint << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment