Skip to content

Instantly share code, notes, and snippets.

View mikedotexe's full-sized avatar
🤙
hakuna matata

Mike Purvis mikedotexe

🤙
hakuna matata
View GitHub Profile
@mikedotexe
mikedotexe / cpython-int-remainder.patch
Created November 26, 2026 04:17
Python patch - reduce four
Subject: [PATCH] Reduce four PyLong digits per division in the one-digit remainder
When only the remainder is needed, reduce blocks of four dividend digits
using the first four powers of PyLong_BASE modulo the divisor. The sum
fits in twodigits for both supported digit widths. Use the existing
digit-at-a-time loop for short dividends and the final partial block.
Base-commit: 22691a32b122cff3ad17460c068f70e806cd7e84
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
@mikedotexe
mikedotexe / gmp-directional-copies.patch
Created November 26, 2026 03:51
GMP patch - directional copies
--- a/mpf/div_ui.c
+++ b/mpf/div_ui.c
@@ -36,14 +36,13 @@
mpf_div_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v)
{
mp_srcptr up;
- mp_ptr rp, tp, rtp;
+ mp_ptr rp;
mp_size_t usize;
- mp_size_t rsize, tsize;
@mikedotexe
mikedotexe / ruby-full-return-example.patch
Created November 26, 2026 02:44
Ruby detect end of reptend
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -4951,6 +4951,7 @@
size_t nLoop;
DECDIG_DBL q, b1, b1p1, b1b2, b1b2p1, r1r2;
DECDIG borrow1, borrow2;
+ DECDIG start = 0;
DECDIG_DBL qb;
VpSetNaN(r);
From 6c2fd2b3373a68a79aabf3a5c49f1d68ff68a877 Mon Sep 17 00:00:00 2001
From: Mike Purvis <mikedotexe@gmail.com>
Date: Wed, 25 Nov 2026 15:41:50 -0800
Subject: [PATCH] math/big: format Rat decimals in blocks for one-word
denominators
FloatString scales the remainder by 10^prec before dividing to get the
fractional digits. When the denominator fits in a Word, the remainder
does too. Use long division to write several decimal digits at a time
without constructing that power of ten.
@mikedotexe
mikedotexe / gmp-qxn.patch
Created November 25, 2026 19:50
GMP qxn patch
--- a/mpf/div_ui.c
+++ b/mpf/div_ui.c
@@ -36,9 +36,9 @@
mpf_div_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v)
{
mp_srcptr up;
- mp_ptr rp, tp, rtp;
+ mp_ptr rp;
mp_size_t usize;
- mp_size_t rsize, tsize;
@mikedotexe
mikedotexe / duckdb.patch
Created November 25, 2026 19:25
DuckDB patch
--- a/extension/core_functions/aggregate/distributive/sum.cpp
+++ b/extension/core_functions/aggregate/distributive/sum.cpp
@@ -7,6 +7,7 @@
#include "duckdb/common/types/decimal_helper.hpp"
#include "duckdb/common/types/hugeint.hpp"
#include "duckdb/common/types/decimal.hpp"
+#include "duckdb/common/vector/sequence_vector.hpp"
#include "duckdb/function/aggregate/distributive_function_utils.hpp"
#include "duckdb/planner/expression/bound_aggregate_expression.hpp"
#include "duckdb/common/serializer/deserializer.hpp"
@mikedotexe
mikedotexe / gmp-tail.patch
Created November 25, 2026 16:50
GMP tail patch
--- a/mpf/div_ui.c
+++ b/mpf/div_ui.c
@@ -82,6 +82,30 @@
up = u->_mp_d;
tsize = 1 + prec;
+
+#if GMP_NAIL_BITS == 0
+ if (tsize - usize >= 24)
+ {
@mikedotexe
mikedotexe / 04-segmented-tail.patch
Created November 25, 2026 01:51
libmpdec - patch 04 for segmented tail
--- a/libmpdec/mpdecimal.c
+++ b/libmpdec/mpdecimal.c
@@ -3749,6 +3749,103 @@
*status |= MPD_Clamped;
}
+/* Divide rem*MPD_RADIX by v, writing one quotient word. */
+static inline mpd_uint_t
+_mpd_shortdiv_zero(mpd_uint_t *q, mpd_uint_t rem, mpd_uint_t v)
+{
@mikedotexe
mikedotexe / 03-short-cycle.patch
Created November 25, 2026 01:50
libmpdec - patch 03 for short cycle
--- a/libmpdec/mpdecimal.c
+++ b/libmpdec/mpdecimal.c
@@ -3749,6 +3749,55 @@
*status |= MPD_Clamped;
}
+/* Divide rem*MPD_RADIX by v, writing one quotient word. */
+static inline mpd_uint_t
+_mpd_shortdiv_zero(mpd_uint_t *q, mpd_uint_t rem, mpd_uint_t v)
+{
@mikedotexe
mikedotexe / calendar_job.py
Created November 25, 2026 01:48
Python converter - UTC convention and inputs
"""Convert a one-Hz UTC clock sequence to two-part Julian dates.
The synthetic inputs cover every UTC second of the final minute on 2016-12-30
(60 labels) or 2016-12-31 (61, including 23:59:60). SOFA's post-1972 UTC
quasi-JD convention maps an entire civil day to one unit, so its fractional
part uses the actual day length. This fixture deliberately covers those two
historical dates only. Julian dates begin at noon, so midnight ends in .5.
https://static1.squarespace.com/static/68caa251ae552a6213e8764b/t/68d3e216e1cf0121bd4273a6/1758716438331/sofa_ts_c.pdf
https://www.nist.gov/pml/time-and-frequency-division/time-realization/leap-seconds