Skip to content

Commit

Permalink
Create cpp/util/other/double-step.cpp and cpp/util/other/float-step.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Sep 16, 2024
1 parent 2492ea7 commit ec1a462
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cpp/util/other/double-step.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @CXXFLAGS -Wno-strict-aliasing -Wno-uninitialized

#include <cstdint>
#include <iostream>

int main()
{
double d;

static_assert(sizeof(double) == sizeof(std::uint64_t));
reinterpret_cast<std::uint64_t&>(d) = 1;

std::cout << d << '\n';

return 0;
}
16 changes: 16 additions & 0 deletions src/cpp/util/other/float-step.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @CXXFLAGS -Wno-strict-aliasing -Wno-uninitialized

#include <cstdint>
#include <iostream>

int main()
{
float f;

static_assert(sizeof(float) == sizeof(std::uint32_t));
reinterpret_cast<std::uint32_t&>(f) = 1;

std::cout << f << '\n';

return 0;
}

0 comments on commit ec1a462

Please sign in to comment.