Skip to content

Instantly share code, notes, and snippets.

@louqash
louqash / keybase.md
Created April 2, 2022 17:13
Keybase proof

Keybase proof

I hereby claim:

  • I am louqash on github.
  • I am louqash (https://keybase.io/louqash) on keybase.
  • I have a public key ASCjwZ8K6_xTlMyuEeU_4D3EWxqKHwEu0POjQzr6dYR9mQo

To claim this, I am signing this object:

@louqash
louqash / ignored_cast.cpp
Last active March 23, 2023 11:47
Gcc ignores cast to signed int16 and float ends up positive
#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;
}
@louqash
louqash / test_floating_point_accuracy.cpp
Last active May 29, 2021 13:53
This gist shows that adding std::numeric_limits<TYPE>::min() to float or double doesn't change the original value, even for as small numbers as 1e-30. This can come useful for calculating logarithms, when one doesn't want `-inf` in the results.
#include <iostream>
#include <limits>
#include <cassert>
#include <cmath>
int main()
{
float f = 1e-30;
float f_plus_min = f + std::numeric_limits<float>::min();