a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * This file and its contents are supplied under the terms of the
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * Common Development and Distribution License ("CDDL"), version 1.0.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * You may only use this file in accordance with the terms of version
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * 1.0 of the CDDL.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * A full copy of the text of the CDDL should have accompanied this
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * source. A copy of the CDDL is also available via the Internet at
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * Copyright 2014 PALO, Richard. All rights reserved.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * Copyright 2014 OmniTI Computer Consulting, Inc. All rights reserved.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * Test rounding of floating point numbers in libc's *printf() routines.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * C99 must be enabled to get DECIMAL_DIG defined, but it looks like all
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * of usr/src/test/libc is compiled that way.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * Returns negative if snprintf() fails. Returns 0 upon
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * successful execution of the test, return 1 upon a failure.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald * Spews output if verbose is TRUE.
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonaldrun_one(test_t t, int i, int j, int precision, boolean_t verbose)
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald /* first get max precision for control check */
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald status = snprintf(check, size, "%+-.*f", DECIMAL_DIG, val);
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald "(i = %d, j = %d) returned %d\n", i, j, status);
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald /* then get specific precision */
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald status = snprintf(buffer, size, "%+-#.*f", precision, val);
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald test_failed(t, "Specific precision snprintf() "
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald "(i = %d, j = %d, precision = %d) returned %d\n", i, j,
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald /* last check if correctly rounded up */
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald buffer[strlen(buffer) - 1] > check[strlen(buffer) - 1]) {
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald "for %02d/%02d => %s (%s)\n",
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald /* NOTE: Any argument after the command enables "VERBOSE" mode. */
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald t = test_start("*printf() floating-point rounding tests.");
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald for (precision = DBL_DIG - 1; precision <= DECIMAL_DIG;
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald test_failed(t, "Tests failed %d times out of %d attempts.\n"
a2290a3621fa5498b33edb7037d8e95c15ddf455Dan McDonald "Run '%s full' to see the %d failures individually.\n",