Created
November 24, 2019 20:46
-
-
Save jmegner/8f1513eaa3f3e54af588af38bdb96a6b to your computer and use it in GitHub Desktop.
Mixed Signedness Math Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdint> | |
#include <cassert> | |
#include <typeinfo> | |
using namespace std; | |
int main() | |
{ | |
const uint16_t u16 = 1; | |
const uint32_t u32 = 1; | |
const uint64_t u64 = 1; | |
const int16_t i16 = 1; | |
const int32_t i32 = 1; | |
const int64_t i64 = 1; | |
const auto& type_int = typeid(int); | |
const auto& type_i32 = typeid(int32_t); | |
const auto& type_i64 = typeid(int64_t); | |
const auto& type_u32 = typeid(uint32_t); | |
const auto& type_u64 = typeid(uint64_t); | |
assert(typeid(int) == type_i32); | |
assert(typeid(u16 + u16) == type_i32); | |
assert(typeid(u16 + u32) == type_u32); | |
assert(typeid(i32 + u16) == type_i32); | |
assert(typeid(i32 + u16) == type_i32); | |
assert(typeid(i32 + u32) == type_u32); | |
assert(typeid(i32 + u64) == type_u64); | |
assert(typeid(i64 + u32) == type_i64); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment