Kudu C++ client API
Loading...
Searching...
No Matches
int128.h
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18// This file is the central location for defining the int128 type
19// used by Kudu. Though this file is small it ensures flexibility
20// as choices and standards around int128 change.
21
22#ifndef KUDU_UTIL_INT128_H_
23#define KUDU_UTIL_INT128_H_
24
25// __int128 is not supported before gcc 4.6
26#if defined(__clang__) || \
27 (defined(__GNUC__) && \
28 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40600)
29#define KUDU_INT128_SUPPORTED 1
30#else
31#define KUDU_INT128_SUPPORTED 0
32#endif
33
34#if KUDU_INT128_SUPPORTED
35namespace kudu {
36
37typedef unsigned __int128 uint128_t;
38typedef signed __int128 int128_t;
39
40// Note: We don't use numeric_limits because it can give incorrect
41// values for __int128 and unsigned __int128.
42static const uint128_t UINT128_MIN = (uint128_t) 0;
43static const uint128_t UINT128_MAX = ((uint128_t) -1);
44static const int128_t INT128_MAX = ((int128_t)(UINT128_MAX >> 1));
45static const int128_t INT128_MIN = (-INT128_MAX - 1);
46
47} // namespace kudu
48#endif
49
50#endif // #ifndef KUDU_UTIL_INT128_H_ ...