chromium/third_party/fdlibm/overflowing-math.h

// Copyright 2019 the V8 project authors. All rights reserved.
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_FDLIBM_OVERFLOWING_MATH_H_
#define THIRD_PARTY_FDLIBM_OVERFLOWING_MATH_H_

#include <stdint.h>

#include <cmath>
#include <type_traits>

namespace fdlibm {

// Helpers for performing overflowing arithmetic operations without relying
// on C++ undefined behavior.
#define ASSERT_SIGNED_INTEGER_TYPE
#define OP_WITH_WRAPAROUND

OP_WITH_WRAPAROUND
OP_WITH_WRAPAROUND
OP_WITH_WRAPAROUND

// 16-bit integers are special due to C++'s implicit conversion rules.
// See https://bugs.llvm.org/show_bug.cgi?id=25580.
template <>
inline int16_t MulWithWraparound(int16_t a, int16_t b) {}

#undef OP_WITH_WRAPAROUND

template <typename signed_type>
inline signed_type NegateWithWraparound(signed_type a) {}

template <typename signed_type>
inline signed_type ShlWithWraparound(signed_type a, signed_type b) {}

#undef ASSERT_SIGNED_INTEGER_TYPE

// Returns the quotient x/y, avoiding C++ undefined behavior if y == 0.
template <typename T>
inline T Divide(T x, T y) {}

inline float Recip(float a) {}

inline float RecipSqrt(float a) {}

template <typename T>
inline T RoundingAverageUnsigned(T a, T b) {}

}  // namespace fdlibm

#endif  // THIRD_PARTY_FDLIBM_OVERFLOWING_MATH_H_