Coverage Report

Created: 2026-08-14 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libsolutil/Numeric.cpp
Line
Count
Source
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
19
#include <libsolutil/Numeric.h>
20
21
#include <liblangutil/Exceptions.h>
22
23
using namespace solidity;
24
25
bool solidity::fitsPrecisionBaseX(bigint const& _mantissa, double _log2OfBase, uint32_t _exp)
26
56.9k
{
27
56.9k
  if (_mantissa == 0)
28
0
    return true;
29
30
56.9k
  solAssert(_mantissa > 0, "");
31
32
56.9k
  size_t const bitsMax = 4096;
33
34
56.9k
  size_t mostSignificantMantissaBit = static_cast<size_t>(boost::multiprecision::msb(_mantissa));
35
56.9k
  if (mostSignificantMantissaBit > bitsMax) // _mantissa >= 2 ^ 4096
36
0
    return false;
37
38
56.9k
  bigint bitsNeeded = mostSignificantMantissaBit + bigint(floor(double(_exp) * _log2OfBase)) + 1;
39
56.9k
  return bitsNeeded <= bitsMax;
40
56.9k
}