src/c/tests/thirdparty/Unity/unity.h
void UnityPrintFloat(const UNITY_DOUBLE input_number)
{
#ifdef UNITY_INCLUDE_DOUBLE
    static const int sig_digits = 9;
    static const UNITY_INT32 min_scaled = 100000000;
    static const UNITY_INT32 max_scaled = 1000000000;
#else
    static const int sig_digits = 7;
    static const UNITY_INT32 min_scaled = 1000000;
    static const UNITY_INT32 max_scaled = 10000000;
#endif

    UNITY_DOUBLE number = input_number;

    /* print minus sign (does not handle negative zero) */
    if (number < 0.0f)
    {
        UNITY_OUTPUT_CHAR('-');
        number = -number;
    }

    /* handle zero, NaN, and +/- infinity */
    if (number == 0.0f)
    {
        UnityPrint("0");
    }
    else if (isnan(number))
    {
        UnityPrint("nan");
    }
    else if (isinf(number))
    {
        UnityPrint("inf");
    }
    else
    {
        UNITY_INT32 n_int = 0, n;
        int exponent = 0;
        int decimals, digits;
        char buf[16] = {0};

        /*
         * Scale up or down by powers of 10.  To minimize rounding error,
         * start with a factor/divisor of 10^10, which is the largest
         * power of 10 that can be represented exactly.  Finally, compute
         * (exactly) the remaining power of 10 and perform one more
         * multiplication or division.
         */
        if (number < 1.0f)
        {
            UNITY_DOUBLE factor = 1.0f;

            while (number < (UNITY_DOUBLE)max_scaled / 1e10f)  { number *= 1e10f; exponent -= 10; }
            while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; }

            number *= factor;
        }
        else if (number > (UNITY_DOUBLE)max_scaled)
        {
            UNITY_DOUBLE divisor = 1.0f;

            while (number > (UNITY_DOUBLE)min_scaled * 1e10f)   { number  /= 1e10f; exponent += 10; }
            while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; }

            number /= divisor;
        }
        else
        {
            /*
             * In this range, we can split off the integer part before
             * doing any multiplications.  This reduces rounding error by
             * freeing up significant bits in the fractional part.
             */
            UNITY_DOUBLE factor = 1.0f;
            n_int = (UNITY_INT32)number;
            number -= (UNITY_DOUBLE)n_int;

            while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; }

            number *= factor;
        }

        /* round to nearest integer */
        n = ((UNITY_INT32)(number + number) + 1) / 2;

#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
        /* round to even if exactly between two integers */
        if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f))
            n--;
#endif

        n += n_int;

        if (n >= max_scaled)
        {
            n = min_scaled;
            exponent++;
        }

        /* determine where to place decimal point */
        decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3))) ? (-exponent) : (sig_digits - 1);
        exponent += decimals;

        /* truncate trailing zeroes after decimal point */
        while ((decimals > 0) && ((n % 10) == 0))
        {
            n /= 10;
            decimals--;
        }

        /* build up buffer in reverse order */
        digits = 0;
        while ((n != 0) || (digits <= decimals))
        {
            buf[digits++] = (char)('0' + n % 10);
            n /= 10;
        }
        while (digits > 0)
        {
            if (digits == decimals) { UNITY_OUTPUT_CHAR('.'); }
            UNITY_OUTPUT_CHAR(buf[--digits]);
        }

        /* print exponent if needed */
        if (exponent != 0)
        {
            UNITY_OUTPUT_CHAR('e');

            if (exponent < 0)
            {
                UNITY_OUTPUT_CHAR('-');
                exponent = -exponent;
            }
            else
            {
                UNITY_OUTPUT_CHAR('+');
            }

            digits = 0;
            while ((exponent != 0) || (digits < 2))
            {
                buf[digits++] = (char)('0' + exponent % 10);
                exponent /= 10;
            }
            while (digits > 0)
            {
                UNITY_OUTPUT_CHAR(buf[--digits]);
            }
        }
    }
}
/*
 * This function prints a floating-point value in a format similar to
 * printf("%.7g") on a single-precision machine or printf("%.9g") on a
 * double-precision machine.  The 7th digit won't always be totally correct
 * in single-precision operation (for that level of accuracy, a more
 * complicated algorithm would be needed).
 */
This function prints a floating-point value in a format similar to
printf("%.7g") on a single-precision machine or printf("%.9g") on a
double-precision machine.  The 7th digit won't always be totally correct
in single-precision operation (for that level of accuracy, a more
complicated algorithm would be needed).
This function prints a floating - point value in a format similar to printf ( " % . 7g " ) on a single - precision machine or printf ( " % . 9g " ) on a double - precision machine . The 7th digit won ' t always be totally correct in single - precision operation ( for that level of accuracy a more complicated algorithm would be needed ) .
void UnityPrintFloat(const UNITY_DOUBLE input_number)
{
#ifdef UNITY_INCLUDE_DOUBLE
    static const int sig_digits = 9;
    static const UNITY_INT32 min_scaled = 100000000;
    static const UNITY_INT32 max_scaled = 1000000000;
#else
    static const int sig_digits = 7;
    static const UNITY_INT32 min_scaled = 1000000;
    static const UNITY_INT32 max_scaled = 10000000;
#endif
    UNITY_DOUBLE number = input_number;
    if (number < 0.0f)
    {
        UNITY_OUTPUT_CHAR('-');
        number = -number;
    }
    if (number == 0.0f)
    {
        UnityPrint("0");
    }
    else if (isnan(number))
    {
        UnityPrint("nan");
    }
    else if (isinf(number))
    {
        UnityPrint("inf");
    }
    else
    {
        UNITY_INT32 n_int = 0, n;
        int exponent = 0;
        int decimals, digits;
        char buf[16] = {0};
        if (number < 1.0f)
        {
            UNITY_DOUBLE factor = 1.0f;
            while (number < (UNITY_DOUBLE)max_scaled / 1e10f)  { number *= 1e10f; exponent -= 10; }
            while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; }
            number *= factor;
        }
        else if (number > (UNITY_DOUBLE)max_scaled)
        {
            UNITY_DOUBLE divisor = 1.0f;
            while (number > (UNITY_DOUBLE)min_scaled * 1e10f)   { number  /= 1e10f; exponent += 10; }
            while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; }
            number /= divisor;
        }
        else
        {
            UNITY_DOUBLE factor = 1.0f;
            n_int = (UNITY_INT32)number;
            number -= (UNITY_DOUBLE)n_int;
            while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; }
            number *= factor;
        }
        n = ((UNITY_INT32)(number + number) + 1) / 2;
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
        if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f))
            n--;
#endif
        n += n_int;
        if (n >= max_scaled)
        {
            n = min_scaled;
            exponent++;
        }
        decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3))) ? (-exponent) : (sig_digits - 1);
        exponent += decimals;
        while ((decimals > 0) && ((n % 10) == 0))
        {
            n /= 10;
            decimals--;
        }
        digits = 0;
        while ((n != 0) || (digits <= decimals))
        {
            buf[digits++] = (char)('0' + n % 10);
            n /= 10;
        }
        while (digits > 0)
        {
            if (digits == decimals) { UNITY_OUTPUT_CHAR('.'); }
            UNITY_OUTPUT_CHAR(buf[--digits]);
        }
        if (exponent != 0)
        {
            UNITY_OUTPUT_CHAR('e');
            if (exponent < 0)
            {
                UNITY_OUTPUT_CHAR('-');
                exponent = -exponent;
            }
            else
            {
                UNITY_OUTPUT_CHAR('+');
            }
            digits = 0;
            while ((exponent != 0) || (digits < 2))
            {
                buf[digits++] = (char)('0' + exponent % 10);
                exponent /= 10;
            }
            while (digits > 0)
            {
                UNITY_OUTPUT_CHAR(buf[--digits]);
            }
        }
    }
}
void UnityPrintFloat ( const UNITY_DOUBLE input_number ) { #ifdef UNITY_INCLUDE_DOUBLE static const int sig_digits = 9 ; static const UNITY_INT32 min_scaled = 100000000 ; static const UNITY_INT32 max_scaled = 1000000000 ; #else static const int sig_digits = 7 ; static const UNITY_INT32 min_scaled = 1000000 ; static const UNITY_INT32 max_scaled = 10000000 ; #endif UNITY_DOUBLE number = input_number ; if ( number < 0.0f ) { UNITY_OUTPUT_CHAR ( ' ' ) ; number = - number ; } if ( number == 0.0f ) { UnityPrint ( " " ) ; } else if ( isnan ( number ) ) { UnityPrint ( " " ) ; } else if ( isinf ( number ) ) { UnityPrint ( " " ) ; } else { UNITY_INT32 n_int = 0 , n ; int exponent = 0 ; int decimals , digits ; char buf [ 16 ] = { 0 } ; if ( number < 1.0f ) { UNITY_DOUBLE factor = 1.0f ; while ( number < ( UNITY_DOUBLE ) max_scaled / 1e10f ) { number *= 1e10f ; exponent -= 10 ; } while ( number * factor < ( UNITY_DOUBLE ) min_scaled ) { factor *= 10.0f ; exponent -- ; } number *= factor ; } else if ( number > ( UNITY_DOUBLE ) max_scaled ) { UNITY_DOUBLE divisor = 1.0f ; while ( number > ( UNITY_DOUBLE ) min_scaled * 1e10f ) { number /= 1e10f ; exponent += 10 ; } while ( number / divisor > ( UNITY_DOUBLE ) max_scaled ) { divisor *= 10.0f ; exponent ++ ; } number /= divisor ; } else { UNITY_DOUBLE factor = 1.0f ; n_int = ( UNITY_INT32 ) number ; number -= ( UNITY_DOUBLE ) n_int ; while ( n_int < min_scaled ) { n_int *= 10 ; factor *= 10.0f ; exponent -- ; } number *= factor ; } n = ( ( UNITY_INT32 ) ( number + number ) + 1 ) / 2 ; #ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO if ( ( n & 1 ) && ( ( ( UNITY_DOUBLE ) n - number ) == 0.5f ) ) n -- ; #endif n += n_int ; if ( n >= max_scaled ) { n = min_scaled ; exponent ++ ; } decimals = ( ( exponent <= 0 ) && ( exponent >= - ( sig_digits + 3 ) ) ) ? ( - exponent ) : ( sig_digits - 1 ) ; exponent += decimals ; while ( ( decimals > 0 ) && ( ( n % 10 ) == 0 ) ) { n /= 10 ; decimals -- ; } digits = 0 ; while ( ( n != 0 ) || ( digits <= decimals ) ) { buf [ digits ++ ] = ( char ) ( ' ' + n % 10 ) ; n /= 10 ; } while ( digits > 0 ) { if ( digits == decimals ) { UNITY_OUTPUT_CHAR ( ' ' ) ; } UNITY_OUTPUT_CHAR ( buf [ -- digits ] ) ; } if ( exponent != 0 ) { UNITY_OUTPUT_CHAR ( ' ' ) ; if ( exponent < 0 ) { UNITY_OUTPUT_CHAR ( ' ' ) ; exponent = - exponent ; } else { UNITY_OUTPUT_CHAR ( ' ' ) ; } digits = 0 ; while ( ( exponent != 0 ) || ( digits < 2 ) ) { buf [ digits ++ ] = ( char ) ( ' ' + exponent % 10 ) ; exponent /= 10 ; } while ( digits > 0 ) { UNITY_OUTPUT_CHAR ( buf [ -- digits ] ) ; } } } }
This function prints a floating-point value in a format similar to
 printf("%.7g") on a single-precision machine or printf("%.9g") on a
 double-precision machine.
This function prints a floating - point value in a format similar to printf ( " % . 7g " ) on a single - precision machine or printf ( " % . 9g " ) on a double - precision machine .
/* print minus sign (does not handle negative zero) */ /* handle zero, NaN, and +/- infinity */ /*
         * Scale up or down by powers of 10.  To minimize rounding error,
         * start with a factor/divisor of 10^10, which is the largest
         * power of 10 that can be represented exactly.  Finally, compute
         * (exactly) the remaining power of 10 and perform one more
         * multiplication or division.
         */ /*
             * In this range, we can split off the integer part before
             * doing any multiplications.  This reduces rounding error by
             * freeing up significant bits in the fractional part.
             */ /* round to nearest integer */ /* round to even if exactly between two integers */ /* determine where to place decimal point */ /* truncate trailing zeroes after decimal point */ /* build up buffer in reverse order */ /* print exponent if needed */