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
enum { | |
BASE = 1000000000, // nine decimals per limb | |
NUMCAP = 1<<16, // capacity just over a half million decimals | |
}; | |
typedef struct { | |
int *digits; | |
int len; | |
} num; |
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 <stddef.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define new(a, t) (t *)alloc(a, sizeof(t)) | |
typedef struct { | |
char *beg, *end; |
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
// Transaction counter | |
// | |
// Input: Null-terminated null-terminated string array. Each string has | |
// three non-negative integers under 1e9: "sender-id receiver-id amount" | |
// The amount field is unused. | |
// | |
// Output: A null-terminated, numerically sorted null-terminated string | |
// array of ids that exceeded a given transaction count threshold. | |
// | |
// Ref: https://old.reddit.com/r/C_Programming/comments/174dwcb |
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
// $ go test -bench=. | |
// goos: windows | |
// goarch: amd64 | |
// pkg: x | |
// cpu: 12th Gen Intel(R) Core(TM) i9-12900 | |
// BenchmarkFixed-24 21196731 54.78 ns/op | |
// BenchmarkVariable-24 10045690 117.7 ns/op | |
// BenchmarkMappedCold-24 14038420 93.53 ns/op | |
// BenchmarkMappedWarm-24 21380121 53.21 ns/op | |
// BenchmarkBytes-24 19775221 82.31 ns/op |
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
// $ eval cc icosphere.c $(pkg-config --cflags --libs sdl2) -lopengl32 | |
// Ref: http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html | |
// Ref: https://old.reddit.com/r/C_Programming/comments/16ionwe | |
#include <math.h> | |
#include <stdint.h> | |
#include <string.h> | |
#define new(h, t, n) (t *)alloc(h, sizeof(t), _Alignof(t), n) | |
typedef struct { |
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
// https://old.reddit.com/r/C_Programming/comments/16ho5ql/implementing_and_simplifying_treap_in_c/ | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define new(h, t) (t *)alloc(h, sizeof(t), _Alignof(t)) | |
#define assert(c) while (!(c)) __builtin_trap() |
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
CC = cc | |
CFLAGS = -w -g3 -DC_ONLY -fcommon -DGAME_HARD_LINKED | |
all: quake2.exe ref_soft.dll | |
game_obj = \ | |
game/g_ai.o game/g_chase.o game/g_cmds.o game/g_combat.o game/g_func.o \ | |
game/g_items.o game/g_main.o game/g_misc.o game/g_monster.o game/g_phys.o \ | |
game/g_save.o game/g_spawn.o game/g_svcmds.o game/g_target.o \ | |
game/g_trigger.o game/g_turret.o game/g_utils.o game/g_weapon.o \ |
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
// SVG generator example | |
// $ cc -DDEMO -o svg svg.c | |
// $ ./svg >demo.svg | |
// Large demo: | |
// $ cc -DBIGDEMO -o svg svg.c | |
// $ ./svg >bigdemo.svg | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <stdint.h> |
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
// Arlet Ottens's 16 byte random generator | |
// $ cc -O3 -o rand16 rand16.c | |
// $ ./rand16 | RNG_test stdin32 | |
// https://github.com/Arlet/pseudo-random-number-generator/blob/main/avr/rand16.S | |
#include <stdint.h> | |
#include <stdio.h> | |
uint32_t rand16(uint8_t s[16]) | |
{ | |
uint8_t t, c, r[32]; |
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 x | |
go 1.21.0 |