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

« back to all changes in this revision

Viewing changes to tests/simulate/printf/sprintf_flt-big.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, very long strings.
2
 
   $Id: sprintf_flt-big.c,v 1.2 2007/03/10 04:44: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 sprf_s {
10
 
    char fmt[8];
11
 
    float val;
12
 
    char pattern[260];
13
 
} t[] = {
14
 
 
15
 
    { "%255e",          1.234567,
16
 
        "                                "      /* 32 */
17
 
        "                                "      /* 32 */
18
 
        "                                "      /* 32 */
19
 
        "                                "      /* 32 */
20
 
        "                                "      /* 32 */
21
 
        "                                "      /* 32 */
22
 
        "                                "      /* 32 */
23
 
        "                   1.234567e+00"       },
24
 
    { "%255.7e",        1.2345678,
25
 
        "                                "      /* 32 */
26
 
        "                                "      /* 32 */
27
 
        "                                "      /* 32 */
28
 
        "                                "      /* 32 */
29
 
        "                                "      /* 32 */
30
 
        "                                "      /* 32 */
31
 
        "                                "      /* 32 */
32
 
        "                  1.2345678e+00"       },
33
 
    { "%+255e",         1.234567,
34
 
        "                                "      /* 32 */
35
 
        "                                "      /* 32 */
36
 
        "                                "      /* 32 */
37
 
        "                                "      /* 32 */
38
 
        "                                "      /* 32 */
39
 
        "                                "      /* 32 */
40
 
        "                                "      /* 32 */
41
 
        "                  +1.234567e+00"       },
42
 
    { "%0255e",         1.234567,
43
 
        "00000000000000000000000000000000"      /* 32 */
44
 
        "00000000000000000000000000000000"      /* 32 */
45
 
        "00000000000000000000000000000000"      /* 32 */
46
 
        "00000000000000000000000000000000"      /* 32 */
47
 
        "00000000000000000000000000000000"      /* 32 */
48
 
        "00000000000000000000000000000000"      /* 32 */
49
 
        "00000000000000000000000000000000"      /* 32 */
50
 
        "00000000000000000001.234567e+00"       },
51
 
    { "%+0255e",        1.234567,
52
 
        "+0000000000000000000000000000000"      /* 32 */
53
 
        "00000000000000000000000000000000"      /* 32 */
54
 
        "00000000000000000000000000000000"      /* 32 */
55
 
        "00000000000000000000000000000000"      /* 32 */
56
 
        "00000000000000000000000000000000"      /* 32 */
57
 
        "00000000000000000000000000000000"      /* 32 */
58
 
        "00000000000000000000000000000000"      /* 32 */
59
 
        "00000000000000000001.234567e+00"       },
60
 
    { "%+0255e",        -1.234567,
61
 
        "-0000000000000000000000000000000"      /* 32 */
62
 
        "00000000000000000000000000000000"      /* 32 */
63
 
        "00000000000000000000000000000000"      /* 32 */
64
 
        "00000000000000000000000000000000"      /* 32 */
65
 
        "00000000000000000000000000000000"      /* 32 */
66
 
        "00000000000000000000000000000000"      /* 32 */
67
 
        "00000000000000000000000000000000"      /* 32 */
68
 
        "00000000000000000001.234567e+00"       },
69
 
    { "%-255e",         1.234567,
70
 
        "1.234567e+00                    "
71
 
        "                                "      /* 32 */
72
 
        "                                "      /* 32 */
73
 
        "                                "      /* 32 */
74
 
        "                                "      /* 32 */
75
 
        "                                "      /* 32 */
76
 
        "                                "      /* 32 */
77
 
        "                               "       },
78
 
 
79
 
    { "%255.0f",        1.25,
80
 
        "                                "      /* 32 */
81
 
        "                                "      /* 32 */
82
 
        "                                "      /* 32 */
83
 
        "                                "      /* 32 */
84
 
        "                                "      /* 32 */
85
 
        "                                "      /* 32 */
86
 
        "                                "      /* 32 */
87
 
        "                              1"       },
88
 
    { "%.255f",         1.25,
89
 
        "1.250000000000000000000000000000"
90
 
        "00000000000000000000000000000000"      /* 32 */
91
 
        "00000000000000000000000000000000"      /* 32 */
92
 
        "00000000000000000000000000000000"      /* 32 */
93
 
        "00000000000000000000000000000000"      /* 32 */
94
 
        "00000000000000000000000000000000"      /* 32 */
95
 
        "00000000000000000000000000000000"      /* 32 */
96
 
        "000000000000000000000000000000000"     },
97
 
    { "%0255f",         1.25,
98
 
        "00000000000000000000000000000000"      /* 32 */
99
 
        "00000000000000000000000000000000"      /* 32 */
100
 
        "00000000000000000000000000000000"      /* 32 */
101
 
        "00000000000000000000000000000000"      /* 32 */
102
 
        "00000000000000000000000000000000"      /* 32 */
103
 
        "00000000000000000000000000000000"      /* 32 */
104
 
        "00000000000000000000000000000000"      /* 32 */
105
 
        "000000000000000000000001.250000"       },
106
 
    { "%-255f",         1.25,
107
 
        "1.250000                        "
108
 
        "                                "      /* 32 */
109
 
        "                                "      /* 32 */
110
 
        "                                "      /* 32 */
111
 
        "                                "      /* 32 */
112
 
        "                                "      /* 32 */
113
 
        "                                "      /* 32 */
114
 
        "                               "       },
115
 
 
116
 
    /* the smallest nonzero     */
117
 
    { "%.45f",          0x1p-149f,
118
 
        "0.000000000000000000000000000000000000000000001"       },
119
 
    { "%.50f",          0x1p-149f,
120
 
        "0.00000000000000000000000000000000000000000000140130"  },
121
 
 
122
 
};
123
 
 
124
 
void run_sprf (const struct sprf_s *pt, int testno)
125
 
{
126
 
    static char s[300];
127
 
    int n;
128
 
    int code;
129
 
 
130
 
#ifdef  __AVR__
131
 
    n = sprintf_P (s, pt->fmt, pgm_read_dword (& pt->val));
132
 
#else
133
 
    n = sprintf (s, pt->fmt, pt->val);
134
 
#endif
135
 
    if (n != (int)strlen_P (pt->pattern))
136
 
        code = testno + 1000;
137
 
    else if (strcmp_P (s, pt->pattern))
138
 
        code = testno;
139
 
    else
140
 
        return;
141
 
#if  !defined(__AVR__)
142
 
    printf ("\ntestno %3d: expect: %3d, \"%s\","
143
 
            "\n            output: %3d, \"%s\"\n",
144
 
            testno, strlen(pt->pattern), pt->pattern, n, s);
145
 
    exit (code < 256 ? testno : 255);
146
 
#elif   defined(DEBUG)
147
 
    exit ((int)s);
148
 
#endif
149
 
    exit (code);
150
 
}
151
 
 
152
 
int main ()
153
 
{
154
 
    int i;
155
 
    for (i = 0; (unsigned)i != sizeof(t)/sizeof(t[0]); i++)
156
 
        run_sprf (t+i, i+1);
157
 
    return 0;
158
 
}