Arkulib
Utils.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <cmath>
12#include <sstream>
13#include "../Constant.hpp"
14
15namespace Arkulib::Tools {
23 template <typename FloatingType = double>
24 auto roundToWantedPrecision(const FloatingType value, const int precision = 10e4) {
25 return std::round(value * precision) / precision;
26 }
27
35 template <typename Type>
37 const Type value,
39 ) {
40 std::ostringstream out;
41 out.precision(precision);
42 out << std::fixed << value;
43 return out.str();
44 }
45
52 template <typename Type>
53 int getNumberLength(const Type value) {
54 return trunc(log10(value));
55 }
56}
const unsigned int DEFAULT_COUT_ERATIONAL_DIGITS
The default precision set for ERational std::cout.
Definition: Constant.hpp:17
auto roundToWantedPrecision(const FloatingType value, const int precision=10e4)
Round a number for a wanted precision (the digits)
Definition: Utils.hpp:24
int getNumberLength(const Type value)
Get the length on a number.
Definition: Utils.hpp:53
std::string toStringWithPrecision(const Type value, const int precision=Arkulib::Constant::DEFAULT_COUT_ERATIONAL_DIGITS)
Let the user set the precision while transforming a floating point to a string.
Definition: Utils.hpp:36