1N/A/*
1N/A * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_IDSTR(id, "@(#)$Id: t-float.c,v 1.16 2001/02/02 23:11:46 ca Exp $")
1N/A
1N/A#include <sm/limits.h>
1N/A#include <sm/io.h>
1N/A#include <sm/string.h>
1N/A#include <sm/test.h>
1N/A#include <sm/types.h>
1N/A
1N/Aint
1N/Amain(argc, argv)
1N/A int argc;
1N/A char **argv;
1N/A{
1N/A double d, d2;
1N/A double ld;
1N/A char buf[128];
1N/A char *r;
1N/A
1N/A /*
1N/A ** Sendmail uses printf and scanf with doubles,
1N/A ** so make sure that this works.
1N/A */
1N/A
1N/A sm_test_begin(argc, argv, "test floating point stuff");
1N/A
1N/A d = 1.125;
1N/A sm_snprintf(buf, sizeof(buf), "%d %.3f %d", 0, d, 1);
1N/A r = "0 1.125 1";
1N/A if (!SM_TEST(strcmp(buf, r) == 0))
1N/A (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1N/A "got %s instead\n", buf);
1N/A
1N/A d = 1.125;
1N/A sm_snprintf(buf, sizeof(buf), "%.3f", d);
1N/A r = "1.125";
1N/A if (!SM_TEST(strcmp(buf, r) == 0))
1N/A (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1N/A "got %s instead\n", buf);
1N/A d2 = 0.0;
1N/A sm_io_sscanf(buf, "%lf", &d2);
1N/A#if SM_CONF_BROKEN_STRTOD
1N/A if (d != d2)
1N/A {
1N/A (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1N/A "wanted %f, got %f\n", d, d2);
1N/A (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1N/A "error ignored since SM_CONF_BROKEN_STRTOD is set for this OS\n");
1N/A }
1N/A#else /* SM_CONF_BROKEN_STRTOD */
1N/A if (!SM_TEST(d == d2))
1N/A (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1N/A "wanted %f, got %f\n", d, d2);
1N/A#endif /* SM_CONF_BROKEN_STRTOD */
1N/A
1N/A ld = 2.5;
1N/A sm_snprintf(buf, sizeof(buf), "%.3f %.1f", d, ld);
1N/A r = "1.125 2.5";
1N/A if (!SM_TEST(strcmp(buf, r) == 0))
1N/A (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1N/A "got %s instead\n", buf);
1N/A return sm_test_end();
1N/A}