8
8
9
9
// #include "src/__support/str_float_conv_utils.h"
10
10
11
- #include < stdlib.h> // For string to float functions
12
-
13
11
// #include "src/__support/FPUtil/FPBits.h"
14
12
15
- #include < cstdint>
16
- #include < fstream>
17
- #include < iostream>
18
- #include < string>
13
+ #include < stdint.h>
14
+ #include < stdio.h>
15
+ #include < stdlib.h>
19
16
20
17
// The intent of this test is to read in files in the format used in this test
21
18
// dataset: https://github.com/nigeltao/parse-number-fxx-test-data
@@ -59,30 +56,31 @@ int checkFile(char *inputFileName, int *totalFails, int *totalBitDiffs,
59
56
int32_t curFails = 0 ; // Only counts actual failures, not bitdiffs.
60
57
int32_t curBitDiffs = 0 ; // A bitdiff is when the expected result and actual
61
58
// result are off by +/- 1 bit.
62
- std::string line;
63
- std::string num;
59
+ char line[ 100 ] ;
60
+ char num[ 100 ] ;
64
61
65
- std::ifstream fileStream (inputFileName, std::ifstream::in );
62
+ auto *fileHandle = fopen (inputFileName, " r " );
66
63
67
- if (!fileStream. is_open () ) {
68
- std::cout << " file '" << inputFileName << " ' failed to open. Exiting.\n " ;
64
+ if (!fileHandle ) {
65
+ printf ( " file '%s ' failed to open. Exiting.\n " , inputFileName) ;
69
66
return 1 ;
70
67
}
71
- while (getline (fileStream, line)) {
68
+
69
+ while (fgets (line, sizeof (line), fileHandle)) {
72
70
if (line[0 ] == ' #' ) {
73
71
continue ;
74
72
}
75
73
*total = *total + 1 ;
76
74
uint32_t expectedFloatRaw;
77
75
uint64_t expectedDoubleRaw;
78
76
79
- expectedFloatRaw = fastHexToU32 (line. c_str () + 5 );
80
- expectedDoubleRaw = fastHexToU64 (line. c_str () + 14 );
81
- num = line. substr ( 31 );
77
+ expectedFloatRaw = fastHexToU32 (line + 5 );
78
+ expectedDoubleRaw = fastHexToU64 (line + 14 );
79
+ sscanf (line + 31 , " %s " , num );
82
80
83
- float floatResult = strtof (num. c_str () , nullptr );
81
+ float floatResult = strtof (num, nullptr );
84
82
85
- double doubleResult = strtod (num. c_str () , nullptr );
83
+ double doubleResult = strtod (num, nullptr );
86
84
87
85
uint32_t floatRaw = *(uint32_t *)(&floatResult);
88
86
@@ -101,9 +99,8 @@ int checkFile(char *inputFileName, int *totalFails, int *totalBitDiffs,
101
99
curFails++;
102
100
}
103
101
if (curFails + curBitDiffs < 10 ) {
104
- std::cout << " Float fail for '" << num << " '. Expected " << std::hex
105
- << expectedFloatRaw << " but got " << floatRaw << " \n "
106
- << std::dec;
102
+ printf (" Float fail for '%s'. Expected %x but got %x\n " , num,
103
+ expectedFloatRaw, floatRaw);
107
104
}
108
105
}
109
106
@@ -120,14 +117,13 @@ int checkFile(char *inputFileName, int *totalFails, int *totalBitDiffs,
120
117
curFails++;
121
118
}
122
119
if (curFails + curBitDiffs < 10 ) {
123
- std::cout << " Double fail for '" << num << " '. Expected " << std::hex
124
- << expectedDoubleRaw << " but got " << doubleRaw << " \n "
125
- << std::dec;
120
+ printf (" Double fail for '%s'. Expected %lx but got %lx\n " , num,
121
+ expectedDoubleRaw, doubleRaw);
126
122
}
127
123
}
128
124
}
129
125
130
- fileStream. close ( );
126
+ fclose (fileHandle );
131
127
132
128
*totalBitDiffs += curBitDiffs;
133
129
*totalFails += curFails;
@@ -151,7 +147,7 @@ int main(int argc, char *argv[]) {
151
147
152
148
int total = 0 ;
153
149
for (int i = 1 ; i < argc; i++) {
154
- std::cout << " Starting file " << argv[i] << " \n " ;
150
+ printf ( " Starting file %s \n " , argv[i]) ;
155
151
int curResult =
156
152
checkFile (argv[i], &fails, &bitdiffs, detailedBitDiffs, &total);
157
153
if (curResult == 1 ) {
@@ -161,13 +157,16 @@ int main(int argc, char *argv[]) {
161
157
result = 2 ;
162
158
}
163
159
}
164
- std::cout << " Results:\n "
165
- << " Total significant failed conversions: " << fails << " \n "
166
- << " Total conversions off by +/- 1 bit: " << bitdiffs << " \n "
167
- << " \t " << detailedBitDiffs[0 ] << " \t float low\n "
168
- << " \t " << detailedBitDiffs[1 ] << " \t float high\n "
169
- << " \t " << detailedBitDiffs[2 ] << " \t double low\n "
170
- << " \t " << detailedBitDiffs[3 ] << " \t double high\n "
171
- << " Total lines: " << total << " \n " ;
160
+ printf (" Results:\n "
161
+ " Total significant failed conversions: %d\n "
162
+ " Total conversions off by +/- 1 bit: %d\n "
163
+ " \t %d\t float low\n "
164
+ " \t %d\t float high\n "
165
+ " \t %d\t double low\n "
166
+ " \t %d\t double high\n "
167
+ " Total lines: %d\n " ,
168
+ fails, bitdiffs, detailedBitDiffs[0 ], detailedBitDiffs[1 ],
169
+ detailedBitDiffs[2 ], detailedBitDiffs[3 ], total);
170
+
172
171
return result;
173
172
}
0 commit comments