blob: d6f0840b59deb5b405f216602a7730bb4dad4dd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
#include "EASTLTest.h"
#include <EASTL/bit.h>
using namespace eastl;
int TestBitcast()
{
int nErrorCount = 0;
{
uint32_t int32Value = 0x12345678;
float floatValue = eastl::bit_cast<float>(int32Value);
VERIFY(memcmp(&int32Value, &floatValue, sizeof(float)) == 0);
}
{
struct IntFloatStruct
{
uint32_t i = 0x87654321;
float f = 10.f;
};
struct CharIntStruct
{
char c1;
char c2;
char c3;
char c4;
uint32_t i;
};
IntFloatStruct ifStruct;
CharIntStruct ciStruct = eastl::bit_cast<CharIntStruct>(ifStruct);
VERIFY(memcmp(&ifStruct, &ciStruct, sizeof(IntFloatStruct)) == 0);
}
#if EASTL_CONSTEXPR_BIT_CAST_SUPPORTED
{
constexpr uint32_t int32Value = 40;
constexpr float floatValue = eastl::bit_cast<float>(int32Value);
VERIFY(memcmp(&int32Value, &floatValue, sizeof(float)) == 0);
}
#endif
return nErrorCount;
}
|