AWS SDK for C++

AWS SDK for C++ Version 1.11.896

Loading...
Searching...
No Matches
NumericUtils.h
1
6#pragma once
7
8#include <cstdint>
9#include <cstdlib>
10#include <limits>
11
12namespace Aws
13{
14 namespace Utils
15 {
16 constexpr double LLONG_MIN_AS_DOUBLE = static_cast<double>((std::numeric_limits<int64_t>::min)());
17 constexpr double LLONG_MAX_PLUS_ONE = -static_cast<double>((std::numeric_limits<int64_t>::min)());
18
19 inline bool IsRepresentableAsInt64(double value)
20 {
21 return value >= LLONG_MIN_AS_DOUBLE && value < LLONG_MAX_PLUS_ONE;
22 }
23
24 inline int64_t ToInt64Saturating(double value)
25 {
26 if (value != value)
27 {
28 return 0;
29 }
30 if (value >= LLONG_MAX_PLUS_ONE)
31 {
32 return (std::numeric_limits<int64_t>::max)();
33 }
34 if (value < LLONG_MIN_AS_DOUBLE)
35 {
36 return (std::numeric_limits<int64_t>::min)();
37 }
38 return static_cast<int64_t>(value);
39 }
40
41 inline int64_t LiteralToInt64(const char* literal, double valuedouble)
42 {
43 char* end = nullptr;
44 const long long parsed = std::strtoll(literal, &end, 10);
45 if (*end == '\0')
46 {
47 return parsed;
48 }
49 return ToInt64Saturating(valuedouble);
50 }
51 }
52}
constexpr double LLONG_MAX_PLUS_ONE
constexpr double LLONG_MIN_AS_DOUBLE
bool IsRepresentableAsInt64(double value)
int64_t LiteralToInt64(const char *literal, double valuedouble)
int64_t ToInt64Saturating(double value)