source: trunk/libs/newlib/src/libgloss/testsuite/libgloss.all/misc.c @ 610

Last change on this file since 610 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.7 KB
Line 
1/*
2 * this file contains misc bug reports from WinBond.
3 */
4#include <stdio.h>
5#include <math.h>
6
7#if unix
8#define pass(x) printf("PASS: %s\n", x);
9#define fail(x) printf("FAIL: %s\n", x);
10#endif
11
12/*
13    The compare operation is error. Because the constant value 1.0 is
14    not correct. It seems compare with 0 in this statement.
15
16HP-UX native:
17   dist is 0.301
18   PASS: float compare
19   *cp = be9a1cac, *cp1 = be9a1cac
20   PASS: float multiple 1
21   PASS: float multiple 2
22   32760 / (-2) = -16380
23   PASS: float divide 1
24   32760 / (-1) = -32760
25   PASS: float divide 1
26    These test only pass if the output matches:
27    Correct output is
28    1.0 = 1.000000E+00, 0.3010 = 3.000000E-01, -1.0 = -1.000000E+0
29    1.0 = 1.000000E+00, 0.3010 = 3.010000E-01, -1.0 = -1.000000E+00
30    These test only pass if the outut matches:
31    Correct output is
32    ans = 1.000000E+00, ans1 = 3.010000E-01, ans2 = -1.000000E+00
33    ans = 1.000000E+00, ans1 = 3.010000E-01, ans2 = -1.000000E+00
34
35
36Test run on Oki:
37
38    dist is 0
39    PASS: float compare
40    *cp = be9a1cac, *cp1 = be9a1cac
41    PASS: float multiple 1
42    PASS: float multiple 2
43    32760 / (-2) = -2147467268
44    PASS: float divide 1
45    32760 / (-1) = 32760
46    PASS: float divide 1
47    These test only pass if the output matches:
48    Correct output is
49    1.0 = 1.000000E+00, 0.3010 = 3.000000E-01, -1.0 = -1.000000E+0
50    1.0 = 1.586860E-318, 0.3010 = -1.009091E-303, -1.0 = 5.290504E-315
51    These test only pass if the outut matches:
52    Correct output is
53    ans = 1.000000E+00, ans1 = 3.010000E-01, ans2 = -1.000000E+00
54    ans = 4.940656E-324, ans1 = -5.299809E-315, ans2 = 5.290504E-315
55
56 */
57
58main()
59{
60  float dist = 0.3010;
61
62  printf ("dist is %G\n", dist);
63  if ( dist < 1.0 ) {
64    pass ("float compare");
65  } else {
66    fail ("float compare");
67  }
68
69  test_1();
70  test_2();
71  test_3();
72  test_4();
73
74  fflush (stdout);
75}
76
77/*
78 *    *cp = be9a1cac, *cp1 = 00000000
79 */
80test_1()
81{
82  float i, ans, ans1;
83  unsigned int *cp=&ans, *cp1=&ans1;
84 
85  i = 0.3010;
86  ans = (-1.0) * 0.3010 * 1.0;        /* OK */
87  ans1 = (-1.0) * i * 1.0;            /* Disaster */
88  printf ("*cp = %08x, *cp1 = %08x\n", *cp, *cp1);
89
90  if (*cp != 0xbe9a1cac) {
91    fail ("float multiple 1");
92  } else {
93    pass ("float multiple 1");
94  }
95
96  if (*cp1 != 0xbe9a1cac) {
97    fail ("float multiple 2");
98  } else {
99    pass ("float multiple 2");
100  }
101}
102
103/*
104    Positive integer divide Negative integer may get interesting result.
105    For examples:
106    EX1: 32760 / (-2) = -2147467268
107 */
108test_2()
109{
110  int value, i, j;
111 
112  i = 32760;
113  j = -2;
114  value = i / (j);
115  printf ("%d / (%d) = %d\n", i, j, value);
116 
117  if (value != -16380) {
118    fail ("float divide 1");
119  } else {
120    pass ("float divide 1");
121  }
122}
123
124/*
125     EX2: 32760 / (-1) = 32760
126 */
127test_3()
128{
129  int value, i, j;
130 
131  i = 32760;
132  j = -1;
133  value = i / (j);
134  printf ("%d / (%d) = %d\n", i, j, value);
135
136  if (value != -32760) {
137    fail ("float divide 1");
138  } else {
139    pass ("float divide 1");
140  }
141}
142
143/*
144    The data output format %e, %E, %g, %G in printf() can not work.
145    Please test the following example:
146
147    1.0 = 1.000000E+00, 0.3010 = 3.009999E-01, -1.0 = -1.000000E+00
148    ans = 4.940656E-324, ans1 = -5.299809E-315, ans2 = 5.290504E-315
149 */
150test_4()
151{
152  float ans, ans1, ans2;
153 
154  ans = 1.0;
155  ans1 = 0.3010;
156  ans2 = -1.0;
157
158  printf ("These test only pass if the output matches:\nCorrect output is\n1.0 = 1.000000E+00, 0.3010 = 3.000000E-01, -1.0 = -1.000000E+0\n");
159  printf ("1.0 = %E, 0.3010 = %E, -1.0 = %E\n", 1.0, 0.3010, -1.0);
160  printf ("These test only pass if the outut matches:\nCorrect output is\nans = 1.000000E+00, ans1 = 3.010000E-01, ans2 = -1.000000E+00\n");
161  printf ("ans = %E, ans1 = %E, ans2 = %E\n", ans, ans1, ans2);
162}
163
164
165
166
167
Note: See TracBrowser for help on using the repository browser.