1570af302Sopenharmony_ci// commit 89740868c9f1c84b8ee528468d12df1fa72cd392 2014-04-07 2570af302Sopenharmony_ci// %g should not print trailing zeros 3570af302Sopenharmony_ci#include <stdio.h> 4570af302Sopenharmony_ci#include <string.h> 5570af302Sopenharmony_ci#include "test.h" 6570af302Sopenharmony_ci 7570af302Sopenharmony_cistatic void t(const char *fmt, double d, const char *want) 8570af302Sopenharmony_ci{ 9570af302Sopenharmony_ci char buf[256]; 10570af302Sopenharmony_ci int n = strlen(want); 11570af302Sopenharmony_ci int r = snprintf(buf, sizeof buf, fmt, d); 12570af302Sopenharmony_ci if (r != n || memcmp(buf, want, n+1) != 0) 13570af302Sopenharmony_ci t_error("snprintf(\"%s\",%f) want %s got %s\n", fmt, d, want, buf); 14570af302Sopenharmony_ci} 15570af302Sopenharmony_ci 16570af302Sopenharmony_ciint main() 17570af302Sopenharmony_ci{ 18570af302Sopenharmony_ci t("%.50g", 100000000000000.5, "100000000000000.5"); 19570af302Sopenharmony_ci t("%.50g", 987654321098765.0, "987654321098765"); 20570af302Sopenharmony_ci return t_status; 21570af302Sopenharmony_ci} 22