Skip to content

Instantly share code, notes, and snippets.

kevinmoran / rand_float.cpp
Created Mar 31, 2021
Converting an integer to a float between 0 and 1 with bithacks (for PRNG)
View rand_float.cpp
// Source: "xoshiro / xoroshiro generators and the PRNG shootout"
#include <stdint.h>
static inline double u64ToDoubleBetween01(uint64_t x) {
return (x >> 11) * 0x1.0p-53;
// I came up with the following function for 32-bit floats based on the above, let me know if it's wrong
kevinmoran / EntityProperties.cpp
Created Jan 21, 2021
Stretchy bitflags - Nifty code snippet from Ryan Fleury shared on Handmade Network discord
View EntityProperties.cpp
enum EntityProperty
kevinmoran / Murmur3.cpp
Created May 27, 2020
Simple MurmurHash3 Implementation (from Demetri Spanos)
View Murmur3.cpp
// Minimal Murmur3 implementation shared by Demetri Spanos on Handmade Network Discord
// Code is deliberately terse and simplistic
// Intended to be the first hash function you reach for e.g. a simple hash table
// @demetrispanos:
// "yes let me reiterate the moral of this story
// there is never any reason to use a dumb made up hash function
// use murmur3 or jenkins-one-at-a-time for a 0-effort version
View WASAPI Play .wav File.cpp
// Simple example code to load a Wav file and play it with WASAPI
// This is NOT complete Wav loading code. It is a barebones example
// that makes a lot of assumptions, see the assert() calls for details
// References:
// Handmade Hero Day 138: Loading WAV Files
#include <windows.h>
View WASAPI Render Sine Wave.cpp
#include <windows.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <assert.h>
#include <math.h> // for sin()
#include <stdint.h>
kevinmoran / cubicSinf.h
Created Oct 9, 2019
Cubic approximation of sinf(), if you only need something sinusoid-ish
View cubicSinf.h
// Source:
float cubicSinf(float x)
float t = x * 0.15915f;
t = t - (int)t;
return 20.785f * t * (t - 0.5f) * (t - 1.f);
kevinmoran / SinApprox.h
Last active Oct 9, 2019
Sin Approximation
View SinApprox.h
// From:
float sinApprox(float x)
const float kPI32 = 3.14159265359f;
const float B = 4/kPI32;
const float C = -4/(kPI32*kPI32);
float y = B * x + C * x * abs(x);