#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int main()
{
  vector<pair<double,const char*>> numbers = {
    { 1234567, "12e5" },
    { 12345.6, "12346" },
    { 1234.56, "1235" },
    { 123.456, "123.5" },
    { 12.3456, "12.35" },
    { 1.23456, "1.235" },
    { 1.23450, "1.235" },
    { 1.23400, "1.234" },
    { 1.23000, "1.23" },
    { 1.20000, "1.2" },
    { 1.00000, "1" },
    { 0.11111, "0.111" },
    { 0.01111, "0.011" },
    { 0.00111, "0.001" },
    { 0.00011, "11e-4" },
    { 0.00001, "1e-5" },
    { 0.11111, "0.111" },
    { 0.01111, "0.011" },
    { 0.00111, "0.001" },
    { 0.00011, "11e-4" },
    { 0.00001, "1e-5" }
  };

  cout << "printf(\"%.3f\");" << endl << endl;

  for (auto& pair : numbers)
  {
    char buf[255];
    std::fill(begin(buf), end(buf), 0);
    sprintf(buf, "%.3f", pair.first);
    bool match = strcmp(buf, pair.second) == 0;
    cout << "match " << match << " in " << pair.first << " out " << buf << " expected " << pair.second << endl;
  }

  cout << endl << "printf(\"%.3g\");" << endl << endl;

  for (auto& pair : numbers)
  {
    char buf[255];
    std::fill(begin(buf), end(buf), 0);
    sprintf(buf, "%.3g", pair.first);
    bool match = strcmp(buf, pair.second) == 0;
    cout << "match " << match << " in " << pair.first << " out " << buf << " expected " << pair.second << endl;
  }

  cout << endl << "printf(\"%.4g\");" << endl << endl;

  for (auto& pair : numbers)
  {
    char buf[255];
    std::fill(begin(buf), end(buf), 0);
    sprintf(buf, "%.4g", pair.first);
    bool match = strcmp(buf, pair.second) == 0;
    cout << "match " << match << " in " << pair.first << " out " << buf << " expected " << pair.second << endl;
  }

  return 0;
}