[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / utils / fpcmp / fpcmp.cpp
blob52bddeedc7597068b08f762fd01b7dd3aad89b4b
1 //===- fpcmp.cpp - A fuzzy "cmp" that permits floating point noise --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // fpcmp is a tool that basically works like the 'cmp' tool, except that it can
10 // tolerate errors due to floating point noise, with the -r and -a options.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/FileUtilities.h"
16 #include "llvm/Support/raw_ostream.h"
17 using namespace llvm;
19 namespace {
20 cl::opt<std::string>
21 File1(cl::Positional, cl::desc("<input file #1>"), cl::Required);
22 cl::opt<std::string>
23 File2(cl::Positional, cl::desc("<input file #2>"), cl::Required);
25 cl::opt<double>
26 RelTolerance("r", cl::desc("Relative error tolerated"), cl::init(0));
27 cl::opt<double>
28 AbsTolerance("a", cl::desc("Absolute error tolerated"), cl::init(0));
31 int main(int argc, char **argv) {
32 cl::ParseCommandLineOptions(argc, argv);
34 std::string ErrorMsg;
35 int DF = DiffFilesWithTolerance(File1, File2, AbsTolerance, RelTolerance,
36 &ErrorMsg);
37 if (!ErrorMsg.empty())
38 errs() << argv[0] << ": " << ErrorMsg << "\n";
39 return DF;