1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose: Passes to atof() a series of strings containing floats,
10** checking that each one is correctly extracted.
11**
12**
13**==========================================================================*/
14
15#include <palsuite.h>
16#include <float.h>
17
18struct testCase
19{
20 float fvalue;
21 char avalue[20];
22};
23
24int __cdecl main(int argc, char **argv)
25{
26 int i = 0;
27 double f = 0;
28 struct testCase testCases[] =
29 {
30 {1234, "1234"},
31 {-1234, "-1234"},
32 {1234e-5, "1234e-5"},
33 {1234e+5, "1234e+5"},
34 {1234e5, "1234E5"},
35 {1234.567e-8, "1234.567e-8"},
36 {1234.567e-8, " 1234.567e-8 foo"},
37 {0,"a12"}
38 };
39
40 /*
41 * Initialize the PAL and return FAIL if this fails
42 */
43 if (0 != (PAL_Initialize(argc, argv)))
44 {
45 return FAIL;
46 }
47
48 for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++)
49 {
50 /*Convert the string to a float.*/
51 f = atof(testCases[i].avalue);
52 double result = f - testCases[i].fvalue;
53
54 if (fabs(result) > FLT_EPSILON)
55 {
56 Fail ("atof misinterpreted \"%s\" as %g instead of %g. result %g fabs %g\n",
57 testCases[i].avalue, f, testCases[i].fvalue, result, fabs(result));
58 }
59 }
60 PAL_Terminate();
61 return PASS;
62}
63
64
65
66
67
68
69
70
71
72
73
74
75
76