brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · ad0cac2 Raw
46 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <algorithm>10 11// __half_positive divides an integer number by 2 as unsigned number for known types.12// It can be an important optimization for lower bound, for example.13 14#include <__cxx03/__algorithm/half_positive.h>15#include <cassert>16#include <cstddef>17#include <limits>18 19#include "test_macros.h"20#include "user_defined_integral.h"21 22namespace {23 24template <class IntType, class UnderlyingType = IntType>25TEST_CONSTEXPR bool test(IntType max_v = IntType(std::numeric_limits<UnderlyingType>::max())) {26    return std::__half_positive(max_v) == max_v / 2;27}28 29}  // namespace30 31int main(int, char**)32{33    {34        assert(test<char>());35        assert(test<int>());36        assert(test<long>());37        assert((test<UserDefinedIntegral<int>, int>()));38        assert(test<std::size_t>());39#if !defined(TEST_HAS_NO_INT128)40        assert(test<__int128_t>());41#endif // !defined(TEST_HAS_NO_INT128)42    }43 44  return 0;45}46