PiotrZSL updated this revision to Diff 512149. PiotrZSL added a comment. Fix review comments
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D147906/new/ https://reviews.llvm.org/D147906 Files: clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp Index: clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp @@ -17,13 +17,17 @@ namespace clang::tidy::bugprone { +static llvm::APFloat getHalf(const llvm::fltSemantics &Semantics) { + return llvm::APFloat(Semantics, 1U) / llvm::APFloat(Semantics, 2U); +} + namespace { AST_MATCHER(FloatingLiteral, floatHalf) { - const auto &Literal = Node.getValue(); + const llvm::APFloat Literal = Node.getValue(); if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle()) - return Literal.convertToFloat() == 0.5f; + return Literal == getHalf(llvm::APFloat::IEEEsingle()); if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble()) - return Literal.convertToDouble() == 0.5; + return Literal == getHalf(llvm::APFloat::IEEEdouble()); return false; } } // namespace
Index: clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp @@ -17,13 +17,17 @@ namespace clang::tidy::bugprone { +static llvm::APFloat getHalf(const llvm::fltSemantics &Semantics) { + return llvm::APFloat(Semantics, 1U) / llvm::APFloat(Semantics, 2U); +} + namespace { AST_MATCHER(FloatingLiteral, floatHalf) { - const auto &Literal = Node.getValue(); + const llvm::APFloat Literal = Node.getValue(); if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle()) - return Literal.convertToFloat() == 0.5f; + return Literal == getHalf(llvm::APFloat::IEEEsingle()); if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble()) - return Literal.convertToDouble() == 0.5; + return Literal == getHalf(llvm::APFloat::IEEEdouble()); return false; } } // namespace
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits