Skip to content

Instantly share code, notes, and snippets.

John Calsbeek Nexuapex

Block or report user

Report or block Nexuapex

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Nexuapex
Nexuapex / kahan3.c
Created Aug 23, 2012
Kahan summation (3-way)
View kahan3.c
float sum(float x0, float x1, float x2)
{
float accum = x0 + x1;
float excess = (accum - x0) - x1;
float addend = x2 - excess;
return accum + addend;
}
@Nexuapex
Nexuapex / dump.lua
Created Jun 17, 2012
Dumping a description of a Lua value
View dump.lua
local dump_table_threshold = 3
local dump_indent = (" "):rep(4)
local dumptable = {
["nil"] = tostring,
["number"] = tostring,
["string"] = function(value) return "\"" .. value .. "\"" end,
["boolean"] = tostring,
["table"] = function(value, depth, markers)
if markers[value] then
@Nexuapex
Nexuapex / reinterpret_f32_i32_sse.cc
Created Feb 18, 2012
Reinterpreting int ⇔ float with SSE
View reinterpret_f32_i32_sse.cc
#include <xmmintrin.h>
inline int as_int_bitwise(float a)
{
return _mm_cvtsi128_si32(_mm_set_ss(a));
}
inline float as_float_bitwise(int a)
{
return _mm_cvtss_f32(_mm_cvtsi32_si128(a));
View icosahedron.cc
static GLfloat const minor = 0.5257311f;
static GLfloat const major = 0.8506508f;
float const icosahedron_position[12][3] = {
{0.f, +minor, +major},
{0.f, +minor, -major},
{0.f, -minor, +major},
{0.f, -minor, -major},
{+major, 0.f, +minor},
{+major, 0.f, -minor},
@Nexuapex
Nexuapex / 7segment.c
Created Oct 29, 2011
7-segment display in 50 lines of C99.
View 7segment.c
#include <stdio.h>
int const schematic[7][7] = {
{0,1,1,1,1,0,0},
{2,0,0,0,0,3,0},
{2,0,0,0,0,3,0},
{0,4,4,4,4,0,0},
{5,0,0,0,0,6,0},
{5,0,0,0,0,6,0},
{0,7,7,7,7,0,0},
You can’t perform that action at this time.