25#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_STORAGE_IMPL_
26#error "This file should not be included directly! Use ElementsKernel/Storage.h instead"
42 std::int64_t factor = std::int64_t(
std::pow(10, max_digits));
43 return std::round(value *
static_cast<T
>(factor)) /
static_cast<T
>(factor);
46template <std::
size_t max_digits,
typename T>
51 T converted_value = size;
53 if (source_unit != target_unit) {
56 double value =
roundToDigits(
static_cast<double>(size_in_bytes) /
static_cast<double>(target_factor), max_digits);
60 return converted_value;
68 T converted_value = size;
70 if (source_unit != target_unit) {
73 double value =
roundToDigits(
static_cast<double>(size_in_bytes) /
static_cast<double>(target_factor),
74 static_cast<size_t>(
log10(
static_cast<double>(target_factor))));
78 return converted_value;
Casting with the correct (closest) rounding.
ELEMENTS_API TargetType numberCast(const SourceType &s)
this function is a number cast. It behaves exactly as a static_cast except when casting from a floati...
ELEMENTS_API T storageConvert(const T &size, StorageType source_unit, StorageType target_unit)
ELEMENTS_API T roundToDigits(const T &value, const std::size_t &max_digits)
ELEMENTS_API std::map< StorageType, std::int64_t > StorageFactor