Path: blob/main/contrib/llvm-project/libc/src/__support/integer_operations.h
213766 views
//===-- Utils for abs and friends -------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIBC_SRC___SUPPORT_INTEGER_OPERATIONS_H9#define LLVM_LIBC_SRC___SUPPORT_INTEGER_OPERATIONS_H1011#include "src/__support/CPP/type_traits.h"12#include "src/__support/macros/attributes.h" // LIBC_INLINE13#include "src/__support/macros/config.h"1415namespace LIBC_NAMESPACE_DECL {1617template <typename T>18LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, T>19integer_abs(T n) {20return (n < 0) ? -n : n;21}2223template <typename T>24LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, void>25integer_rem_quo(T x, T y, T ", T &rem) {26quot = x / y;27rem = x % y;28}2930} // namespace LIBC_NAMESPACE_DECL3132#endif // LLVM_LIBC_SRC___SUPPORT_INTEGER_OPERATIONS_H333435