Blame src/regression/printf-fmt-g-zeros.c
|
Szabolcs Nagy |
79bf86 |
// commit 89740868c9f1c84b8ee528468d12df1fa72cd392 2014-04-07
|
|
Szabolcs Nagy |
79bf86 |
// %g should not print trailing zeros
|
|
Szabolcs Nagy |
79bf86 |
#include <stdio.h>
|
|
Szabolcs Nagy |
79bf86 |
#include <string.h>
|
|
Szabolcs Nagy |
79bf86 |
#include "test.h"
|
|
Szabolcs Nagy |
79bf86 |
|
|
Szabolcs Nagy |
79bf86 |
static void t(const char *fmt, double d, const char *want)
|
|
Szabolcs Nagy |
79bf86 |
{
|
|
Szabolcs Nagy |
79bf86 |
char buf[256];
|
|
Szabolcs Nagy |
79bf86 |
int n = strlen(want);
|
|
Szabolcs Nagy |
79bf86 |
int r = snprintf(buf, sizeof buf, fmt, d);
|
|
Szabolcs Nagy |
79bf86 |
if (r != n || memcmp(buf, want, n+1) != 0)
|
|
Szabolcs Nagy |
79bf86 |
t_error("snprintf(\"%s\",%f) want %s got %s\n", fmt, d, want, buf);
|
|
Szabolcs Nagy |
79bf86 |
}
|
|
Szabolcs Nagy |
79bf86 |
|
|
Szabolcs Nagy |
79bf86 |
int main()
|
|
Szabolcs Nagy |
79bf86 |
{
|
|
Szabolcs Nagy |
79bf86 |
t("%.50g", 100000000000000.5, "100000000000000.5");
|
|
Szabolcs Nagy |
79bf86 |
t("%.50g", 987654321098765.0, "987654321098765");
|
|
Szabolcs Nagy |
79bf86 |
return t_status;
|
|
Szabolcs Nagy |
79bf86 |
}
|