| 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-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file contains the declaration of 64-bit unsigned fractional type |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_LIBC_SRC___SUPPORT_FRAC64_H |
| 15 | #define LLVM_LIBC_SRC___SUPPORT_FRAC64_H |
| 16 | |
| 17 | #include "src/__support/big_int.h" |
| 18 | #include "src/__support/macros/config.h" |
| 19 | |
| 20 | namespace LIBC_NAMESPACE_DECL { |
| 21 | |
| 22 | struct Frac64 : public UInt<64> { |
| 23 | using UInt<64>::UInt; |
| 24 | |
| 25 | LIBC_INLINE constexpr Frac64 operator~() const { return Frac64(~val[0]); } |
| 26 | |
| 27 | LIBC_INLINE constexpr Frac64 operator+(Frac64 other) const { |
| 28 | return Frac64(val[0] + other.val[0]); |
| 29 | } |
| 30 | |
| 31 | LIBC_INLINE constexpr Frac64 operator-(Frac64 other) const { |
| 32 | return Frac64(val[0] - other.val[0]); |
| 33 | } |
| 34 | |
| 35 | LIBC_INLINE constexpr Frac64 operator*(Frac64 other) const { |
| 36 | UInt<64> r = UInt<64>::quick_mul_hi(other: UInt<64>(other)); |
| 37 | return Frac64(r.val[0]); |
| 38 | } |
| 39 | |
| 40 | LIBC_INLINE constexpr Frac64 &operator+=(Frac64 other) { |
| 41 | *this = *this + other; |
| 42 | return *this; |
| 43 | } |
| 44 | |
| 45 | LIBC_INLINE constexpr Frac64 &operator-=(Frac64 other) { |
| 46 | *this = *this - other; |
| 47 | return *this; |
| 48 | } |
| 49 | |
| 50 | LIBC_INLINE constexpr Frac64 &operator*=(Frac64 other) { |
| 51 | *this = *this * other; |
| 52 | return *this; |
| 53 | } |
| 54 | |
| 55 | LIBC_INLINE constexpr Frac64 operator<<(size_t s) const { |
| 56 | return Frac64(val[0] << s); |
| 57 | } |
| 58 | |
| 59 | LIBC_INLINE constexpr Frac64 operator>>(size_t s) const { |
| 60 | return Frac64(val[0] >> s); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | } // namespace LIBC_NAMESPACE_DECL |
| 65 | |
| 66 | #endif // LLVM_LIBC_SRC___SUPPORT_FRAC64_H |
| 67 |