UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMNativeRational.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
8#include "VVMNativeRational.generated.h"
9
10// Used to represent integer rational numbers in Verse.
11USTRUCT()
13{
15
16 UPROPERTY()
17 int64 Numerator{0};
18
19 UPROPERTY()
20 int64 Denominator{0};
21
23 {
24 int64 A = Numerator;
25 int64 B = Denominator;
26 while (B)
27 {
28 int64 Remainder = A % B;
29 A = B;
30 B = Remainder;
31 }
32
33 FVerseRational Result;
34 Result.Numerator = Numerator / A;
35 Result.Denominator = Denominator / A;
36
37 if (Result.Denominator < 0 && Result.Numerator != INT64_MIN && Result.Denominator != INT64_MIN)
38 {
39 Result.Numerator = -Result.Numerator;
40 Result.Denominator = -Result.Denominator;
41 }
42
43 return Result;
44 }
45
46 friend bool operator==(const FVerseRational& A, const FVerseRational& B)
47 {
50 return ReducedA.Numerator == ReducedB.Numerator
51 && ReducedA.Denominator == ReducedB.Denominator;
52 }
53
55 {
57 // Make sure that integers hash the same whether represented as an int64 or a FVerseRational.
58 const uint32 NumeratorHash = GetTypeHash(R.Numerator);
59 return R.Denominator == 1
61 : HashCombineFast(NumeratorHash, GetTypeHash(R.Denominator));
62 }
63
65 {
67 FStructuredArchive::FSlot NumeratorField = Record.EnterField(TEXT("Numerator"));
68 NumeratorField << R.Numerator;
69 FStructuredArchive::FSlot DenominatorField = Record.EnterField(TEXT("Denominator"));
70 DenominatorField << R.Denominator;
71 }
72};
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
constexpr uint32 HashCombineFast(uint32 A, uint32 B)
Definition TypeHash.h:74
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition StructuredArchiveSlots.h:144
Definition StructuredArchiveSlots.h:52
UE_API FStructuredArchiveRecord EnterRecord()
Definition StructuredArchiveSlots.h:252
Definition VVMNativeRational.h:13
FVerseRational ReduceAndNormalizeSigns() const
Definition VVMNativeRational.h:22
friend void operator<<(FStructuredArchive::FSlot Slot, FVerseRational &R)
Definition VVMNativeRational.h:64
friend uint32 GetTypeHash(const FVerseRational &R)
Definition VVMNativeRational.h:54
friend bool operator==(const FVerseRational &A, const FVerseRational &B)
Definition VVMNativeRational.h:46
int64 Numerator
Definition VVMNativeRational.h:17