Skip to content

Instantly share code, notes, and snippets.

View hamsham's full-sized avatar

Miles Lacey hamsham

View GitHub Profile
@hamsham
hamsham / cuda_math.h
Created August 18, 2015 06:26
Basic Linear Algebra functions for CUDA
#include <math.h>
__device__ inline float clampf(const float n, const float minVal, const float maxVal)
{
return (n < minVal ? minVal : n) > maxVal ? maxVal : n;
}
@hamsham
hamsham / cuda_raymarcher.cu
Last active December 23, 2019 15:19
A basic ray marcher using CUDA
/*
* A small raymarcher using CUDA
*
* This program renders a dynamically-generated image to a PPM file.
*
* nvcc cuda_raymarcher.cu -arch=sm_20 -o cuda_raymarcher
*/
#include <assert.h>
@hamsham
hamsham / sfml_music.cpp
Created November 15, 2015 08:15
A simple example of playing an audio file using SFML2
/**
* Testing the audio API in SFML
*
* g++ -std=c++11 -Wall -Werror -Wextra -pedantic-errors sfmusic.cpp -o sfmusic -lsfml-audio -lsfml-system
*/
#include <sys/stat.h>
#include <iostream>
@hamsham
hamsham / static_map.cpp
Created November 15, 2015 08:21
This test is to see if a std::map can be populated at program startup before main() is reached.
/**
* This test is to see if a std::map can be populated at program startup before
* main() is reached.
*
* g++ -std=c++11 -Wall -Werror -Wextra -pedantic-errors static_map.cpp -o static_map
*/
#include <map>
#include <iostream>
@hamsham
hamsham / c_generics.c
Created November 15, 2015 08:23
A simple test to see how generics are used in C11
/* testing type-generic math */
/*
* gcc -std=c11 -Wall -Wextra -Werror -pedantic -pedantic-errors c_generics.c -o c_generics
*/
#include <stdio.h>
/******************************************************************************
@hamsham
hamsham / aspect.cpp
Created November 15, 2015 08:27
Test to automatically get the aspect ratio of a display
// Test to automatically get the aspect ratio of a display
// g++ -std=c++11 -pedantic-errors -Wall -Wextra -Werror aspect.cpp -o aspect
#include <cmath>
#include <iostream>
template <typename int_t>
int_t gcd(int_t a, int_t b) {
while (b) {
@hamsham
hamsham / avgnum.cpp
Created November 15, 2015 08:28
Compile-time test to get the average of an arbitrary set of numbers.
/**
* Simple test to get the average of an arbitrary set of numbers
*
* g++ -std=c++11 -Wall -Werror -Wextra -pedantic -pedantic-errors avgnum.cpp -o avgnum
*/
#include <iostream>
#define TEST_NUM 42
@hamsham
hamsham / bn_add.cpp
Created November 15, 2015 08:32
Testing the addition and subtraction of Big Numbers
/*
* Bignum Addition Test
* g++ -std=c++11 -Wall -Werror -Wextra -pedantic -pedantic-errors bignum_add.cpp -o bignum_add
*/
#include <utility> // std::move
#include <string> // std::string
#include <iostream> // std::cout
#include <cstdint> // uint8_t, uint16_t, UINT8_MAX
@hamsham
hamsham / bn_mul.cpp
Created November 15, 2015 08:32
Testing Big-Num multiplication (naive method)
/**
* Bignum multiplication
*
* g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors bn_mul.cpp -o bn_mul
*
* usage: ./bn_mul 123456789 987654321
*/
#include <cstring>
@hamsham
hamsham / dotprod.c
Created November 15, 2015 08:33
Test to help visualize the result of a vector dot product.
/**
* Testing the result of a dot product
*
* gcc -std=c99 -Wall -Werror -Wextra -pedantic -pedantic-errors dotprod.c -o dotprod
*/
#include <stdio.h>
typedef struct vector