8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / t-float.c
blobb4d416ab979720695a379da5e2ed3a07d2f23dec
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 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include <sm/gen.h>
13 SM_IDSTR(id, "@(#)$Id: t-float.c,v 1.16 2001/02/02 23:11:46 ca Exp $")
15 #include <sm/limits.h>
16 #include <sm/io.h>
17 #include <sm/string.h>
18 #include <sm/test.h>
19 #include <sm/types.h>
21 int
22 main(argc, argv)
23 int argc;
24 char **argv;
26 double d, d2;
27 double ld;
28 char buf[128];
29 char *r;
32 ** Sendmail uses printf and scanf with doubles,
33 ** so make sure that this works.
36 sm_test_begin(argc, argv, "test floating point stuff");
38 d = 1.125;
39 sm_snprintf(buf, sizeof(buf), "%d %.3f %d", 0, d, 1);
40 r = "0 1.125 1";
41 if (!SM_TEST(strcmp(buf, r) == 0))
42 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
43 "got %s instead\n", buf);
45 d = 1.125;
46 sm_snprintf(buf, sizeof(buf), "%.3f", d);
47 r = "1.125";
48 if (!SM_TEST(strcmp(buf, r) == 0))
49 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
50 "got %s instead\n", buf);
51 d2 = 0.0;
52 sm_io_sscanf(buf, "%lf", &d2);
53 #if SM_CONF_BROKEN_STRTOD
54 if (d != d2)
56 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
57 "wanted %f, got %f\n", d, d2);
58 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
59 "error ignored since SM_CONF_BROKEN_STRTOD is set for this OS\n");
61 #else /* SM_CONF_BROKEN_STRTOD */
62 if (!SM_TEST(d == d2))
63 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
64 "wanted %f, got %f\n", d, d2);
65 #endif /* SM_CONF_BROKEN_STRTOD */
67 ld = 2.5;
68 sm_snprintf(buf, sizeof(buf), "%.3f %.1f", d, ld);
69 r = "1.125 2.5";
70 if (!SM_TEST(strcmp(buf, r) == 0))
71 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
72 "got %s instead\n", buf);
73 return sm_test_end();