Skip to content

Instantly share code, notes, and snippets.

View reportbase's full-sized avatar

Tom Brinkman reportbase

View GitHub Profile
@reportbase
reportbase / echo
Created March 22, 2015 21:01
printf overloads for floats
struct echo
{
void operator()(const float* a, int size)
{
for(int n = 0; n < size; ++n)
printf("%15d%15.5f\n", n, a[n]);
}
void operator()(const float* a, const float* b, int size)
@reportbase
reportbase / rs_32f test
Created March 22, 2015 21:05
rs32f test
inline void rs32f_test(const char*, const char*, void*, node<message*>** errors)
{
int status;
float data[] = {43.13, 42.66, 43.42, 44.57, 44.22, 44.18, 44.03, 45.35, 45.78, 46.45, 45.71, 46.25,
46.21, 45.64, 46.22, 46.41, 46.03, 46.00, 46.28, 46.28, 45.61, 46.03, 45.89, 46.08,
45.84, 45.42, 45.10, 44.83, 44.33, 43.61, 44.15, 44.09, 44.34
};
float rs [] = {0.60701822435637, 0.49431092655862, 0.594999156777, 0.8336246868167,
0.72025005002827, 0.70824775083558, 0.66638402420065, 1.01705518638599, 1.20787462282414,
@reportbase
reportbase / ema32f test
Created March 22, 2015 21:05
ema32 test
inline void ema32f_test(const char*, const char*, void*, node<message*>** errors)
{
int status = ippStsNoErr;
float data[] = {22.17, 22.40, 23.10, 22.68, 23.33, 23.10, 23.19, 23.65, 23.87, 23.82, 23.63,
23.95, 23.83, 23.75, 24.05, 23.36, 22.61, 22.38, 22.39, 22.15, 22.29, 22.24, 22.43, 22.23,
22.13, 22.18, 22.17, 22.08, 22.19, 22.27
};
float expected [] = {22.9155602300309, 23.0806847255934, 23.2313924423919, 23.2611240962568,
23.3901516732027, 23.4044076005811, 23.4725870673769, 23.5360508601273, 23.5099066068223,
@reportbase
reportbase / get_path_queue
Created March 22, 2015 21:06
returns the path queue
/*
DT_BLK This is a block device.
DT_CHR This is a character device.
DT_DIR This is a directory.
DT_FIFO This is a named pipe (FIFO).
DT_LNK This is a symbolic link.
DT_REG This is a regular file.
DT_SOCK This is a UNIX domain socket.
DT_UNKNOWN The file type is unknown.
*/
@reportbase
reportbase / trim.js
Created March 22, 2015 21:09
trim strings
inline char* ltrim(char* const s)
{
int len;
char* cur;
if(s && *s)
{
len = strlen(s);
cur = s;
@reportbase
reportbase / is_negative
Created March 22, 2015 21:11
is float negative?
inline bool is_negative(float x)
{
unsigned int* ui = (unsigned int*)&x;
return (*ui & 0x80000000) != 0;
}
@reportbase
reportbase / ispowerof2
Created March 22, 2015 21:11
Is power of 2?
inline bool ispowerof2(int i)
{
return i > 0 && (i & (i - 1)) == 0;
}
@reportbase
reportbase / count bits
Created March 22, 2015 21:12
count bits
template<unsigned char b>
struct ByteBits
{
enum
{
COUNT = ((b >> 0) & 1) +
((b >> 1) & 1) +
((b >> 2) & 1) +
((b >> 3) & 1) +
((b >> 4) & 1) +
@reportbase
reportbase / shuffle
Created March 22, 2015 21:13
random shuffle of array
inline void shuffle(int* card, int cardsn)
{
for(int n = 0; n < cardsn; n++)
{
int adj = cardsn - n;
int m = (rand() % adj) + n;
int tmp = card[n];
card[n] = card[m];
card[m] = tmp;
}
@reportbase
reportbase / reverse_string
Created March 22, 2015 21:13
reverse a string
inline void reverse_string(char* A)
{
#define SWAPVAR(A,B) (A^=B, B^=A, A^=B)
char* B = A;
while(B && *B) ++B;
for(--B; A < B; ++A, --B) SWAPVAR(*A, *B);
}