Import sendmail 8.13.4 into a new contrib directory as the first step
[dragonfly.git] / contrib / sendmail-8.13.4 / libsm / t-float.c
blobf3f059b1a1e178083c4109d34e85b0fd87d47cc2
1 /*
2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
10 #include <sm/gen.h>
11 SM_IDSTR(id, "@(#)$Id: t-float.c,v 1.18 2001/09/11 04:04:49 gshapiro Exp $")
13 #include <sm/limits.h>
14 #include <sm/io.h>
15 #include <sm/string.h>
16 #include <sm/test.h>
17 #include <sm/types.h>
19 int
20 main(argc, argv)
21 int argc;
22 char **argv;
24 double d, d2;
25 double ld;
26 char buf[128];
27 char *r;
30 ** Sendmail uses printf and scanf with doubles,
31 ** so make sure that this works.
34 sm_test_begin(argc, argv, "test floating point stuff");
36 d = 1.125;
37 sm_snprintf(buf, sizeof(buf), "%d %.3f %d", 0, d, 1);
38 r = "0 1.125 1";
39 if (!SM_TEST(strcmp(buf, r) == 0))
40 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
41 "got %s instead\n", buf);
43 d = 1.125;
44 sm_snprintf(buf, sizeof(buf), "%.3f", d);
45 r = "1.125";
46 if (!SM_TEST(strcmp(buf, r) == 0))
47 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
48 "got %s instead\n", buf);
49 d2 = 0.0;
50 sm_io_sscanf(buf, "%lf", &d2);
51 #if SM_CONF_BROKEN_STRTOD
52 if (d != d2)
54 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
55 "wanted %f, got %f\n", d, d2);
56 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
57 "error ignored since SM_CONF_BROKEN_STRTOD is set for this OS\n");
59 #else /* SM_CONF_BROKEN_STRTOD */
60 if (!SM_TEST(d == d2))
61 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
62 "wanted %f, got %f\n", d, d2);
63 #endif /* SM_CONF_BROKEN_STRTOD */
65 ld = 2.5;
66 sm_snprintf(buf, sizeof(buf), "%.3f %.1f", d, ld);
67 r = "1.125 2.5";
68 if (!SM_TEST(strcmp(buf, r) == 0))
69 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
70 "got %s instead\n", buf);
71 return sm_test_end();