AaronMiller
|
codepad
|
|
AaronMiller
|
Saved pastes by AaronMiller:
#include <stdint.h>
#include <stdio.h>
int muldiv(int a, int b, int c) {
int abh, abl;
|
view (40 lines, 10 lines of output) |
【Kud】
「Nishizono-san, hello! Would you care for some green tea?」
【Voice】
「Not so fast!」
|
view (84 lines) |
// Select which engine to use for rendering
// 0: Nuclear Fusion will be used -- shows the bugs
// 1: Raw Direct3D 9 will be used -- shows how it's supposed to look
#define D3D9_MODE 0
|
view (784 lines, 1 comment) |
Repeat this riff a bit. Timing is a bit odd, try to get a
feel for what sounds right.
e||
B||
|
view (18 lines) |
// http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
#include <stdio.h>
#include <stdlib.h>
#define haszero(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
|
view (27 lines, 13 lines of output) |
#line 2
#include <stdio.h>
#include <stdlib.h>
char *int_to_string(int n, int radix) {
|
view (66 lines, 14 lines of output) |
float _fsel_branchless(float f, float x, float y) {
unsigned int msk, res;
msk = -(((*(unsigned int *)&f)>>31)&1);
res = ((msk)&*(unsigned int *)&y)|((~msk)&*(unsigned int *)&x);
|
view (16 lines) |
#include <cmath>
#include <cstdio>
#include <cstdlib>
inline float clamp(float x, float lo, float hi) {
|
view (23 lines, 5 lines of output) |
#if _WIN32
# define WIN32_LEAN_AND_MEAN 1
# include <windows.h>
#else
# include <sys/mman.h>
|
view (106 lines, 2 lines of output) |
#include <stdio.h>
#include <stdlib.h>
#if _MSC_VER || __INTEL_COMPILER
# include <intrin.h>
|
view (27 lines, 3 lines of output) |
#include <GL/glfw.h>
#if _WIN32
# define WIN32_LEAN_AND_MEAN 1
# include <windows.h>
#endif
|
view (309 lines) |
#include <stdio.h>
/*
* http://www.opengl.org/archives/resources/faq/technical/transformations.htm#tran0005
*/
|
view (21 lines, 5 lines of output) |
/* rcp-sqrt magic value: 0x5F3759DF */
#include <stdio.h>
void DispIntFloat(unsigned int i) {
printf("0x%.8X = %f\n", i, *(float *)&i);
|
view (15 lines, 2 lines of output) |
#include <stdio.h>
float CopySign(float a, float b) {
union { unsigned int i; float f; } A, B;
|
view (27 lines, 6 lines of output) |
/* "!a ? x : y" Optimization -- No Branching
Written by Aaron J. Miller, 2012 */
#include <stdio.h>
#define selfromzero__(a) (-(((a) ^ -(a)) >> (sizeof(a)*8 - 1)))
|
view (19 lines, 6 lines of output) |
/*
* Software Renderer Test -- Slight Revision
* Written by Aaron J. Miller <nocannedmeat@gmail.com>; 20120309
* !!! MAY BE BUGGY; IS DEFINITELY INCOMPLETE !!!
*
|
view (751 lines) |
#define memory(p,n) (!(p)&&(n) ? malloc((n)) : (p)&&(n) ? realloc((p), (n)) : (free((p)), (void *)0))
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
|
view (42 lines, 8 lines of output) |
#include <stdio.h>
int cpucount() {
#if __i386__||__i386||i386 || __x86_64__||__x86_64||x86_64
int r;
|
view (16 lines, 1 line of output, 2 comments) |
Non-branching check for zero (1 if zero, 0 otherwise):
(a ^ (-a)) >> (sizeof(a)*8 - 1)
If you need an entire mask (e.g., 1111 1111 1111 1111) if zero, then:
|
view (40 lines, 1 comment) |
#include <stdio.h>
/* rightmost zero-bit index */
int rmzbi(int bitfield) {
int result;
|
view (75 lines, 19 lines of output, 1 comment) |
#include <stdio.h>
#include <string.h>
int sum(int x, int y) { return x+y; }
int dif(int x, int y) { return x-y; }
|
view (29 lines, 2 lines of output) |
/*
When selecting between two values without branching (e.g., in a virtual machine),
you can use a specific bit (or bit pattern) to select between the two values, like
so:
|
view (44 lines, 5 lines of output) |
ALLFLAGS := -Wall -Weffc++
DEBUGFLAGS := -g -DDEBUG -D_DEBUG
RELEASEFLAGS := -O3 -s -fomit-frame-pointer -DNDEBUG
CFLAGS := $(ALLFLAGS) $(DEBUGFLAGS)
|
view (28 lines) |
#include <cstdio>
// create a compressed float
// NOTE: in g++, references to this with constants are
// automatically converted to constants, so this
|
view (23 lines, 1 line of output) |
// includes
#include <stdio.h>
// perform the pattern test
int wildcard(const char *source, const char *pattern) {
|
view (73 lines, 7 lines of output, 2 comments) |
//from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms680582%28v=vs.85%29.aspx
//see also: http://msdn.microsoft.com/en-us/library/windows/desktop/ms679351%28v=vs.85%29.aspx
void ErrorExit(LPTSTR lpszFunction)
{
|
view (35 lines) |
#include <cstdio>
#include <cstdarg>
inline void debugf_int(const char *file, unsigned int line, const char *fmt, ...) {
static char buf[8192];
|
view (30 lines, 3 lines of output) |
#include <stdio.h>
#include <stdarg.h>
void debugf_int(const char *file, unsigned int line, const char *format, ...) {
static char buf[8192];
|
view (23 lines, 3 lines of output) |
#include <stdio.h>
int get_xy(int *x, int *y) { *x=4; *y=5; }
#define tvar(a,b) ___temporary_var__##a##__##b##___
#define stringify(x) #x
|
view (19 lines, 1 line of output) |
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define VERSION_MAJOR 1
#define VERSION_MINOR 1
|
view (14 lines, 1 line of output, 1 comment) |
#ifndef __bool_true_false_are_defined
# define __bool_true_false_are_defined 1
typedef enum { false=0, true=1 } bool;
#endif
|
view (11 lines, 1 line of output) |
#include <stdbool.h>
#ifndef __bool_true_false_are_defined
# define __bool_true_false_are_defined 1
typedef enum { false=0, true=1 } bool;
|
view (13 lines, 1 line of output) |
#ifndef __bool_true_false_are_defined
# define __bool_true_false_are_defined 1
typedef enum { false=0, true=1 } bool;
#endif
|
view (13 lines, 1 line of output) |
#include <stdio.h>
#define XOR_SWAP(a, b) (((a) == (b)) || (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))))
#define XOR_PTRSWAP(a,b) {\
union { void *p; size_t n; } __tA_##a = { .p=(void *)(a) },\
|
view (36 lines, 2 lines of output) |
#include <stdio.h>
#define XOR_SWAP(a, b) (((a) == (b)) || (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))))
int main() {
|
view (13 lines, 2 lines of output) |
#include <stdio.h>
#define XOR_SWAP(a, b) (((a) == (b)) || (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))))
int main() {
|
view (13 lines, 2 lines of output) |
#include <cstdio>
inline unsigned int IntAbs(int x) { return ((x+(x>>31))^(x>>31)); }
static int _CalculateAngle(int center_x, int center_y, int extent_x, int extent_y) {
|
view (43 lines, 8 lines of output) |
/*
* C versus C++ test
* Structures with initializations based on field names
*/
#ifdef __cplusplus
|
view (19 lines, 2 lines of output) |
/*
* C versus C++ test
* Structures with initializations based on field names
*/
#ifdef __cplusplus
|
view (19 lines, 2 lines of output) |
/*
* Matrix Math (Column-major notation; row-major storage)
* Written by Aaron J. Miller (20110914)
*
* All of the following routines (less helper functions) should create
|
view (434 lines, 15 lines of output) |
/*
* THANK YOU: http://predef.sourceforge.net/preos.html
*/
#include <stddef.h> /* size_t */
#include <errno.h>
|
view (120 lines, 1 line of output) |
#ifndef assert
# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h> /* fprintf */
# include <stdlib.h> /* exit */
# include <errno.h> /* errno */
|
view (32 lines, 4 lines of output) |
#include <stdio.h>
#define BEGIN_IFACE(T)\
typedef struct T {\
IFACE_FUNC(capture, int, (struct T *));\
|
view (19 lines, 1 line of output) |
Programming Language Idea
This is a class declaration. Note the usage of an uppercase letter as the first character.
Vec3 x y z.
|
view (68 lines) |
(define-syntax defun
(syntax-rules ()
((defun a b ...) (define a (lambda b ...)))))
(defun get-sum (x y) (+ x y))
|
view (7 lines, 1 line of output) |
/*
Music Theory - Practice Algorithms
Written by Aaron J. Miller (aaron.miller@axiosoftonline.com), 2010
Octave 1 - 110Hz (1x)
|
view (152 lines, 262 lines of output) |
/* Includes */
#include <stdio.h>
/* Check whether compilation is in C or C++ */
#if !defined(__cplusplus) && !defined(cplusplus)
|
view (45 lines, 1 line of output) |
/*
THEORY: Converting a real number to a "percentage" and
finding the greatest common factor between the
percentage and the base-percentage (in this case
the value * ACCURACY and ACCURACY) will result
|
view (55 lines, 2 lines of output) |
/*
Written by Aaron J. Miller, 2010
NOTE
The Linux system call gets through before the stdout stream is flushed. You will therefore see the results of that first.
*/
|
view (62 lines, 14 lines of output) |