Last active
March 23, 2023 11:47
-
-
Save louqash/307ef6996ba91ed0e0813b4a9d260fcb to your computer and use it in GitHub Desktop.
Gcc ignores cast to signed int16 and float ends up positive
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> | |
int main() { | |
uint8_t a = 0x80; | |
uint8_t b = 0x01; | |
float c = (float)(((int16_t)a << 8) | b); | |
std::cout << c << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment