diff --git a/TP/4-Templates/Solution/exercice37.cpp b/TP/4-Templates/Solution/exercice37.cpp index da436ccd6231cb02ec4609b7d46585869d3e5e05..6f8a9624779aa5c5940ec05af9c4f1cadcc37242 100644 --- a/TP/4-Templates/Solution/exercice37.cpp +++ b/TP/4-Templates/Solution/exercice37.cpp @@ -174,20 +174,41 @@ private: }; -//! Returns `number` * (2 ^ `exponent`) -int times_power_of_2(int number, int exponent); +int times_power_of_2(int number, int exponent) +{ + while (exponent > 0) + { + number *= 2; + exponent -= 1; + } + while (exponent < 0) + { + number /= 2; + exponent += 1 ; + } + + return number; +} + +int round_as_int(double x) +{ + return static_cast<int>(std::round(x)); +} -//! Round to `x` the nearest integer. -int round_as_int(double x); +int max_int(int Nbits) +{ + return (times_power_of_2(1, Nbits) - 1); +} -//! Maximum integer that might be represented with `Nbits` bits. -int max_int(int Nbits); +[[noreturn]] void error(std::string explanation) +{ + std::cout << "ERROR: " << explanation << std::endl; + exit(EXIT_FAILURE); +} -//! Function to call when an error occurred; its aborts the program. -[[noreturn]] void error(std::string explanation); //! Class which stores several `TestDisplay` as pointers. @@ -252,41 +273,6 @@ int main(int argc, char** argv) /************************************/ -int times_power_of_2(int number, int exponent) -{ - while (exponent > 0) - { - number *= 2; - exponent -= 1; - } - while (exponent < 0) - { - number /= 2; - exponent += 1 ; - } - - return number; -} - - -int round_as_int(double x) -{ - return static_cast<int>(std::round(x)); -} - - -int max_int(int Nbits) -{ - return (times_power_of_2(1, Nbits) - 1); -} - - -[[noreturn]] void error(std::string explanation) -{ - std::cout << "ERROR: " << explanation << std::endl; - exit(EXIT_FAILURE); -} - /*==================================*/ // PowerOfTwoApprox