Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/tests/lib/libm



At Wed, 15 Oct 2014 19:48:53 +0100,
David Laight wrote:
> > Module Name:	src
> > Committed By:	gson
> > Date:		Tue Oct  7 16:53:44 UTC 2014
> > 
> > Modified Files:
> > 	src/tests/lib/libm: t_exp.c
> > 
> > Log Message:
> > In the exp2_values test case, provide separate expected return values
> > for the float case, reflecting the actual exp2f() argument value after
> > rounding to float precision.  Fixes PR lib/49256.  Thanks to Makoto
> > Kamada and Tetsuya Isaki for the analysis.
> 
> The reason I left the tests failing is that the results should be more
> accurate than the values that are actually returned.
> 
> Changing the 'expected' values so that the tests pass is just wrong.
> 
> What I should have got araound to doing is using the x87 instruction
> to generate accurate 64bit mantissa (long double) results for the
> values, and then looked at the sizes of the error terms.
> 
> I think the values ought to be accurate to one or two counts on the lsb
> of the mantissa.

It is not an acuuracy problem of result, is an implicit type cast
problem of argument.

exp2()'s argument is double and exp2f()'s is float.

As you know,
exp2(7.7) means exp2((double)7.7) and
exp2f(7.7) means exp2f((float)7.7).

(double)7.7 = 0x1.ecccccccccccdp+2 in "%a" format
            = 7.7                  in "%.16g" format
            = 7.7000000000000002   in "%.17g" format.

(float)7.7  = 0x1.ecccccp+2 in "%a" format
            = 7.7           in "%.7g" format
            = 7.6999998     in "%.8g" format.

exp2((double)7.7)  = 0x1.9fdf8bcce533ep+7 = 207.9366 (%.7g) = 207.93661 (%.8g)
exp2((float)7.7)   = 0x1.9fdf883275843p+7 = 207.9366 (%.7g) = 207.93659 (%.8g)
exp2f((double)7.7) = 0x1.9fdf88p+7        = 207.9366 (%.7g) = 207.93658 (%.8g)
exp2f((float)7.7)  = 0x1.9fdf88p+7        = 207.9366 (%.7g) = 207.93658 (%.8g)

In the original code (t_exp.c,v 1.6), you execute exp2f(7.7) i.e.,
exp2f((float)7.7), but use 2^((double)7.7) as its expected value.
It's obviously wrong.
For exp2f((float)7.7) is 2^((float)7.7).

Please also see the following sample code.

By the way, in general:
Please write more details in comment at least if you're really
leaving such a failure intentionally, Or as a better way,
please send-pr it and use atf_tc_expect_fail("PR/xxxxx") feature.

Thank you.

-------------------------
% cat a.c
#include <stdio.h>
#include <stdint.h>
#include <math.h>

void print_float(const char *msg, float v)
{
    printf("%s = %-20a = %.7g (%%.7g) = %.8g (%%.8g)\n", msg, v, v, v);
}

void print_double(const char *msg, double v)
{
    printf("%s = %-20a = %.7g (%%.7g) = %.8g (%%.8g)\n", msg, v, v, v);
}

int main(int ac, char *av[])
{
    float  f = 7.7;
    double d = 7.7;
    float f1;
    float f2;

    printf("(double)7.7 = %-20a = %.16g (%%.16g) = %.17g (%%.17g)\n", d, d, d);
    printf("(float)7.7  = %-20a = %.7g (%%.7g)  = %.8g (%%.8g)\n", f, f, f);
    printf("\n");

    print_double("exp2((double)7.7) ", exp2(d));
    print_double("exp2((float)7.7)  ", exp2(f));
    print_float("exp2f((double)7.7)", exp2f(d));
    print_float("exp2f((float)7.7) ", exp2f(f));
    printf("\n");

    f1 = exp2(d);
    f2 = exp2f(f);
    printf("(float)exp2((double)7.7) = %.8g = 0x%08x\n", f1, *(uint32_t*)&f1);
    printf("       exp2f((float)7.7) = %.8g = 0x%08x\n", f2, *(uint32_t*)&f2);
    return 0;
}

% uname -srm
NetBSD 6.1.4_PATCH amd64
% gcc a.c -lm && ./a.out
(double)7.7 = 0x1.ecccccccccccdp+2 = 7.7 (%.16g) = 7.7000000000000002 (%.17g)
(float)7.7  = 0x1.ecccccp+2        = 7.7 (%.7g)  = 7.6999998 (%.8g)

exp2((double)7.7)  = 0x1.9fdf8bcce533ep+7 = 207.9366 (%.7g) = 207.93661 (%.8g)
exp2((float)7.7)   = 0x1.9fdf883275843p+7 = 207.9366 (%.7g) = 207.93659 (%.8g)
exp2f((double)7.7) = 0x1.9fdf88p+7        = 207.9366 (%.7g) = 207.93658 (%.8g)
exp2f((float)7.7)  = 0x1.9fdf88p+7        = 207.9366 (%.7g) = 207.93658 (%.8g)

(float)exp2((double)7.7) = 207.93661 = 0x434fefc6
       exp2f((float)7.7) = 207.93658 = 0x434fefc4
%
-------------------------
---
Tetsuya Isaki <isaki%pastel-flower.jp@localhost / isaki%NetBSD.org@localhost>


Home | Main Index | Thread Index | Old Index