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
/* | |
random64() is a random integer function | |
this code uses undefined behavior but it'll be alright | |
make sure to include stdint | |
*/ | |
#include <stdint.h> | |
// mask to (-2,2] | |
// this is just an example, change the exponent bits for other ranges | |
inline double _22() { |
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
// based on V8 https://v8.dev/blog/math-random. | |
uint64_t state0 = 0x4D696B696E6C6579; | |
uint64_t state1 = 0x0000004873696E67; | |
uint64_t xorshift128plus() { | |
uint64_t s1 = state0; | |
uint64_t s0 = state1; | |
state0 = s0; | |
s1 ^= s1 << 23; | |
s1 ^= s1 >> 17; | |
s1 ^= s0; |
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> | |
#define BYTES_PER_PIXEL 3 | |
#define FILE_HEADER_SIZE 14 | |
#define INFO_HEADER_SIZE 40 | |
/* | |
Generates and saves a bitmap image. | |
- *image - ptr to array of 8 bit image data. unsigned char image[HEIGHT][WIDTH][BYTES_PER_PIXEL] | |
up to down > left to right > blue, green, red |
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
function numToWord(num) { | |
if (!Number.isSafeInteger(num) || num < 0) return null | |
if (!num) return 'zero ' | |
const ntt = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen '] | |
let mstr = '' | |
let nArr = num.toString().padStart(18, '0').match(/.{1,3}/g) | |
for (let i = 5; i > -1; i--) { | |
let wkv = nArr.shift() | |
if (!+wkv) continue | |
if (+wkv[0]) mstr += ntt[+wkv[0]] + 'hundred ' |
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
function useBlack(r, g, b) { | |
const e = v => Math.pow(v / 255 + 0.055, 2.4) | |
r < 11 ? r /= 15496 : r = e(r) / 5.348631 | |
g < 11 ? g /= 4606. : g = e(g) / 1.589931 | |
b < 11 ? b /= 45631 : b = e(b) / 15.74957 | |
return r + g + b > 0.17912878 | |
} |