~ubuntu-branches/ubuntu/wily/avr-libc/wily-proposed

« back to all changes in this revision

Viewing changes to tests/simulate/printf/sprintf_flt-nan.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091031115210-crjd42sn6ezrj52c
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test of sprintf(), float version, nonfinite numbers.
2
 
   $Id: sprintf_flt-nan.c,v 1.1 2007/02/18 13:46:34 dmix Exp $  */
3
 
 
4
 
#include <stdio.h>
5
 
#include <stdlib.h>
6
 
#include <string.h>
7
 
#include "progmem.h"
8
 
 
9
 
PROGMEM static const struct sprfu_s {
10
 
    char fmt[8];
11
 
    union {
12
 
        long lo;
13
 
        float fl;
14
 
    } val;
15
 
    char pattern[21];
16
 
} t[] = {
17
 
 
18
 
    { "%e",     { 0x7f800000 },         "inf"   },
19
 
    { "%e",     { 0xff800000 },         "-inf"  },
20
 
    { "%f",     { 0x7f800000 },         "inf"   },
21
 
    { "%G",     { 0xff800000 },         "-INF"  },
22
 
 
23
 
    { "%e",     { 0x7f800001 },         "nan"   },
24
 
    { "% e",    { 0x7f800001 },         " nan"  },
25
 
    { "%+e",    { 0x7f800001 },         "+nan"  },
26
 
    { "%E",     { 0x7f800001 },         "NAN"   },
27
 
    { "%5e",    { 0x7f800001 },         "  nan" },
28
 
    { "%+5e",   { 0x7f800001 },         " +nan" },
29
 
    { "%05e",   { 0x7f800001 },         "  nan" },
30
 
    { "%-5e",   { 0x7f800001 },         "nan  " },
31
 
 
32
 
    { "%e",     { 0xff800001 },         "nan"   },
33
 
    { "% e",    { 0xff800001 },         " nan"  },
34
 
    { "%+e",    { 0xff800001 },         "+nan"  },
35
 
    { "%E",     { 0xff800001 },         "NAN"   },
36
 
    { "%5e",    { 0xff800001 },         "  nan" },
37
 
    { "%+5e",   { 0xff800001 },         " +nan" },
38
 
    { "%05e",   { 0xff800001 },         "  nan" },
39
 
    { "%-5e",   { 0xff800001 },         "nan  " },
40
 
 
41
 
    { "%e",     { 0x7fffffff },         "nan"   },
42
 
    { "%e",     { 0xffffffff },         "nan"   },
43
 
    { "%e",     { 0x7fc00000 },         "nan"   },
44
 
    { "%e",     { 0xffc00000 },         "nan"   },
45
 
 
46
 
    { "%f",     { 0x7f800001 },         "nan"   },
47
 
    { "%5F",    { 0x7f800001 },         "  NAN" },
48
 
    { "%g",     { 0x7f800001 },         "nan"   },
49
 
    { "%5G",    { 0x7f800001 },         "  NAN" },
50
 
};
51
 
 
52
 
#ifndef __AVR__
53
 
# define strlen_P       strlen
54
 
#endif
55
 
 
56
 
void run_sprf (const struct sprfu_s *pt, int testno)
57
 
{
58
 
    static char s[300];
59
 
    int n;
60
 
    int code;
61
 
 
62
 
#ifdef  __AVR__
63
 
    n = sprintf_P (s, pt->fmt, pgm_read_dword (& pt->val));
64
 
#else
65
 
    n = sprintf (s, pt->fmt, pt->val.fl);
66
 
#endif
67
 
    if (n != (int)strlen_P (pt->pattern))
68
 
        code = testno + 1000;
69
 
    else if (strcmp_P (s, pt->pattern))
70
 
        code = testno;
71
 
    else
72
 
        return;
73
 
#if  !defined(__AVR__)
74
 
    printf ("\ntestno %3d: expect: %3d, \"%s\","
75
 
            "\n            output: %3d, \"%s\"\n",
76
 
            testno, strlen(pt->pattern), pt->pattern, n, s);
77
 
    exit (code < 256 ? testno : 255);
78
 
#elif   defined(DEBUG)
79
 
    exit ((int)s);
80
 
#endif
81
 
    exit (code);
82
 
}
83
 
 
84
 
int main ()
85
 
{
86
 
    int i;
87
 
    for (i = 0; (unsigned)i != sizeof(t)/sizeof(t[0]); i++)
88
 
        run_sprf (t+i, i+1);
89
 
    return 0;
90
 
}