26 #include <system_error> 31 return (C ==
'+' || C ==
'-');
39 case 'E':
return true;
40 default:
return false;
46 case '0':
case '1':
case '2':
case '3':
case '4':
47 case '5':
case '6':
case '7':
case '8':
case '9':
48 case '.':
return true;
53 static const char *
BackupNumber(
const char *Pos,
const char *FirstChar) {
58 bool HasPeriod =
false;
85 const char *F1End,
const char *F2End,
86 double AbsTolerance,
double RelTolerance,
87 std::string *ErrorMsg) {
88 const char *F1NumEnd, *F2NumEnd;
89 double V1 = 0.0,
V2 = 0.0;
93 while (isspace(static_cast<unsigned char>(*F1P)) && F1P != F1End)
95 while (isspace(static_cast<unsigned char>(*F2P)) && F2P != F2End)
107 V1 = strtod(F1P, const_cast<char**>(&F1NumEnd));
108 V2 = strtod(F2P, const_cast<char**>(&F2NumEnd));
110 if (*F1NumEnd ==
'D' || *F1NumEnd ==
'd') {
114 StrTmp[
static_cast<unsigned>(F1NumEnd-F1P)] =
'e';
116 V1 = strtod(&StrTmp[0], const_cast<char**>(&F1NumEnd));
117 F1NumEnd = F1P + (F1NumEnd-&StrTmp[0]);
120 if (*F2NumEnd ==
'D' || *F2NumEnd ==
'd') {
124 StrTmp[
static_cast<unsigned>(F2NumEnd-F2P)] =
'e';
126 V2 = strtod(&StrTmp[0], const_cast<char**>(&F2NumEnd));
127 F2NumEnd = F2P + (F2NumEnd-&StrTmp[0]);
131 if (F1NumEnd == F1P || F2NumEnd == F2P) {
133 *ErrorMsg =
"FP Comparison failed, not a numeric difference between '";
135 *ErrorMsg +=
"' and '";
152 if (Diff > RelTolerance) {
155 <<
"Compared: " << V1 <<
" and " <<
V2 <<
'\n' 156 <<
"abs. diff = " <<
std::abs(V1-
V2) <<
" rel.diff = " << Diff <<
'\n' 157 <<
"Out of tolerance: rel/abs: " << RelTolerance <<
'/' 165 F1P = F1NumEnd; F2P = F2NumEnd;
179 double AbsTol,
double RelTol,
180 std::string *
Error) {
184 if (std::error_code EC = F1OrErr.
getError()) {
186 *Error = EC.message();
192 if (std::error_code EC = F2OrErr.
getError()) {
194 *Error = EC.message();
204 const char *F1P = File1Start;
205 const char *F2P = File2Start;
210 if (A_size == B_size &&
215 if (AbsTol == 0 && RelTol == 0) {
217 *Error =
"Files differ without tolerance allowance";
221 bool CompareFailed =
false;
224 while (F1P < File1End && F2P < File2End && *F1P == *F2P) {
229 if (F1P >= File1End || F2P >= File2End)
break;
239 if (
CompareNumbers(F1P, F2P, File1End, File2End, AbsTol, RelTol, Error)) {
240 CompareFailed =
true;
247 bool F1AtEnd = F1P >= File1End;
248 bool F2AtEnd = F2P >= File2End;
249 if (!CompareFailed && (!F1AtEnd || !F2AtEnd)) {
258 if (
CompareNumbers(F1P, F2P, File1End, File2End, AbsTol, RelTol, Error))
259 CompareFailed =
true;
262 if (F1P < File1End || F2P < File2End)
263 CompareFailed =
true;
266 return CompareFailed;
Represents either an error or a value T.
This class represents lattice values for constants.
static const char * BackupNumber(const char *Pos, const char *FirstChar)
size_t getBufferSize() const
static const char * EndOfNumber(const char *Pos)
EndOfNumber - Return the first character that is not part of the specified number.
int DiffFilesWithTolerance(StringRef FileA, StringRef FileB, double AbsTol, double RelTol, std::string *Error=nullptr)
DiffFilesWithTolerance - Compare the two files specified, returning 0 if the files match...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
static bool CompareNumbers(const char *&F1P, const char *&F2P, const char *F1End, const char *F2End, double AbsTolerance, double RelTolerance, std::string *ErrorMsg)
CompareNumbers - compare two numbers, returning true if they are different.
std::error_code getError() const
static bool isNumberChar(char C)
static bool isSignedChar(char C)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
const char * getBufferEnd() const
Merge contiguous icmps into a memcmp
APFloat abs(APFloat X)
Returns the absolute value of the argument.
const char * getBufferStart() const
Provides ErrorOr<T> smart pointer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
static bool isExponentChar(char C)