Skip to content

Instantly share code, notes, and snippets.

View ExaGraphica's full-sized avatar

Exagraph ExaGraphica

View GitHub Profile
@ExaGraphica
ExaGraphica / FastLog2.ts
Last active April 18, 2026 01:19
FastLog2 - A function that computes the (approximate) base-2 logarithm of a given integer.
// FastLog2 - by Exagraph
// A function that computes the (approximate) base-2 logarithm of a given integer.
// For use in Data Compression and Information Theory projects.
const QuickLogTable = new Float64Array([
0, 0, 1, 1.584962500721156, 2, 2.321928094887362, 2.584962500721156, 2.807354922057604, 3, 3.169925001442312, 3.321928094887362, 3.4594316186372973, 3.584962500721156, 3.700439718141092, 3.807354922057604, 3.9068905956085187, 4, 4.087462841250339, 4.169925001442312, 4.247927513443585, 4.321928094887363, 4.392317422778761, 4.459431618637297, 4.523561956057013, 4.584962500721156, 4.643856189774724, 4.700439718141092, 4.754887502163468, 4.807354922057604, 4.857980995127572, 4.906890595608519, 4.954196310386875, 5, 5.044394119358453, 5.087462841250339, 5.129283016944966, 5.169925001442312, 5.20945336562895, 5.247927513443585, 5.285402218862249, 5.321928094887363, 5.357552004618084, 5.392317422778761, 5.426264754702098, 5.459431618637297, 5.491853096329675, 5.523561956057013, 5.554588851677638, 5.58
@ExaGraphica
ExaGraphica / Logistic12.ts
Created November 30, 2025 06:41
12-bit Logistic Approximation
// 12-bit Logistic Approximation - by Exagraph
// An implementation of an approximate Logistic function and its inverse.
// For use in Context Mixing data compressors, equivalent to “squash” and “stretch” in PAQ compressors.
const Y = new Uint16Array([
1, 2, 3, 5, 8, 13, 23, 38, 63, 105, 173, 283, 455, 712, 1070, 1527, 2048, 2569, 3026, 3384, 3641, 3813, 3923, 3991, 4033, 4058, 4073, 4083, 4088, 4091, 4093, 4094, 4095
]);
function Logistic(x){
if(x >= 2047) return 4095;