mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Enable modernize-std-numbers clang-tidy checker, fix findings
This commit is contained in:
parent
414728cc71
commit
b4cbda4e02
3 changed files with 6 additions and 5 deletions
|
@ -64,7 +64,6 @@ Checks: [-*,
|
|||
# These are features in newer version of C++ that we don't have
|
||||
# access to yet.
|
||||
-modernize-use-std-format,
|
||||
-modernize-use-std-numbers,
|
||||
-modernize-use-std-print,
|
||||
]
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/broker/Data.h"
|
||||
|
@ -86,13 +87,13 @@ bool BloomFilter::DoUnserializeData(BrokerDataView data) {
|
|||
}
|
||||
|
||||
size_t BasicBloomFilter::M(double fp, size_t capacity) {
|
||||
double ln2 = std::log(2);
|
||||
double ln2 = std::numbers::ln2;
|
||||
return std::ceil(-(capacity * std::log(fp) / ln2 / ln2));
|
||||
}
|
||||
|
||||
size_t BasicBloomFilter::K(size_t cells, size_t capacity) {
|
||||
double frac = static_cast<double>(cells) / static_cast<double>(capacity);
|
||||
return std::ceil(frac * std::log(2));
|
||||
return std::ceil(frac * std::numbers::ln2);
|
||||
}
|
||||
|
||||
bool BasicBloomFilter::Empty() const { return bits->AllZero(); }
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
#include <utility>
|
||||
|
||||
#include "zeek/Reporter.h"
|
||||
|
@ -13,7 +14,7 @@
|
|||
namespace zeek::probabilistic::detail {
|
||||
|
||||
int CardinalityCounter::OptimalB(double error, double confidence) const {
|
||||
double initial_estimate = 2 * (log(1.04) - log(error)) / log(2);
|
||||
double initial_estimate = 2 * (log(1.04) - log(error)) / std::numbers::ln2;
|
||||
int answer = (int)floor(initial_estimate);
|
||||
|
||||
// k is the number of standard deviations that we have to go to have
|
||||
|
@ -24,7 +25,7 @@ int CardinalityCounter::OptimalB(double error, double confidence) const {
|
|||
do {
|
||||
answer++;
|
||||
k = pow(2, (answer - initial_estimate) / 2);
|
||||
} while ( erf(k / sqrt(2)) < confidence );
|
||||
} while ( erf(k / std::numbers::sqrt2) < confidence );
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue