This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ZEROF(x) ((x)*(x) < 1.0e-15) | |
#define EQF(a, b) ((ZEROF(a) && ZEROF(b)) || ZEROF(((a)-(b))*((a)-(b))/((a)*(a) + ((b)*(b))))) | |
#define LTF(a, b) ((a) < (b) || EQF((a), (b))) | |
#define ASSERT(cond, msg, ...) { numtest_assert(cond, test_ctx, __FILE__, __LINE__, __FUNCTION__, msg, ##__VA_ARGS__); } | |
#define ASSERT_EQF(a, b, msg, ...) ASSERT(EQF((a), (b)), msg, ##__VA_ARGS__) | |
#define ASSERT_LTF(a, b, msg, ...) ASSERT(LTF((a), (b)), msg, ##__VA_ARGS__) | |
#define ASSERT_RANGEF(x, min, max, msg, ...) ASSERT(LTF((min), (x)) && LTF((x), (max)), msg, ##__VA_ARGS__) | |
struct numtest_ctx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct kepler_elements { | |
double semi_latus_rectum; | |
double eccentricity; | |
double mean_motion; | |
double inclination; | |
double longitude_of_ascending_node; | |
double argument_of_periapsis; | |
double periapsis_time; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int julian(int y, int m, int d) { | |
return 367*y - | |
(7 * (y + (m+9)/12))/4 - | |
(3 * ((y + (m-9)/7)/100 + 1))/4 + | |
275*m/9 + d + 1721029; | |
} | |
void gregorian(int j, int *year, int *month, int *day) { | |
int a = j + 68569; | |
int b = 4*a / 146097; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 420 | |
uniform mat4 projection_matrix; | |
uniform mat4 model_matrix; | |
void main() | |
{ | |
int tri = gl_VertexID / 3; | |
int idx = gl_VertexID % 3; | |
int face = tri / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib(n) = | |
if n <= 1 | |
then n // TODO: is "then" keyword required? not strictly but improves readability? | |
else | |
left = fib(n-2) | |
right = fib(n-1) | |
left + right | |
fib_iter(n) = | |
iter(a, b, n) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Debug.Trace | |
import Control.Monad (forM_) | |
epsilon = 1.0e-10 :: Double | |
add (x1, y1, z1) (x2, y2, z2) = (x1+x2, y1+y2, z1+z2) | |
sub (x1, y1, z1) (x2, y2, z2) = (x1-x2, y1-y2, z1-z2) | |
mul (x1, y1, z1) (x2, y2, z2) = (x1*x2, y1*y2, z1*z2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <errno.h> | |
#ifdef __linux__ | |
#define _GNU_SOURCE | |
#define __USE_GNU |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
static float mad(float a, float b, float c) | |
{ | |
return a * b + c; | |
} | |
static void step1(const float *vel0, const float *a, float *d, float *v, float *delta, float *vel, float dt, size_t n) | |
{ | |
for(size_t i = 0; i < n; ++i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void integrate_euler(float t0, float dt, float x0, float v0, float *x, float *v, float(*accelerate)(float,float,float)) | |
{ | |
float a = accelerate(t0, x0, v0); | |
float dx = v0 * dt + 0.5 * a * dt * dt; | |
float dv = a * dt; | |
*x = x0 + dx; | |
*v = v0 + dv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pprint import PrettyPrinter | |
pprint = PrettyPrinter().pprint | |
def load_craft(filename): | |
stack = [(None, [], [])] | |
with open(filename) as f: | |
prev = None | |
for line in f: |