首页›research!rsc›文章

Fast Unrounded Scaling: Proof by Ivy

Russ Cox · 2026年1月19日

AI 摘要 AI 生成,可能有误

本文证明了 uscale 的正确性。uscale 是一种基于 64×128 位乘法与浮点近似的快速无舍入缩放算法,它是作者的浮点数打印与解析算法(FixedWidth、Short 和 Parse)的基础。该证明通过一系列引理展开,依次处理精确结果、较小的正幂与负幂,最后处理无法直接穷举测试的大幂次情形。对于这些大幂次情形,作者使用 Ivy 计算器——一种受 APL 启发、支持任意精度有理数和从右到左优先级的语言——来实现一种两步方法,大致遵循 Vern Paxson 和 Tim Peters 的工作,该方法通过求解“模搜索”问题找到第一个满足条件的值,并通过求解“模最小值”问题验证所有相关输入。

My post “Floating-Point Printing and Parsing Can Be Simple And Fast” depends on fast unrounded scaling, defined as:

The unrounded form of , , is the integer value of concatenated with two more bits: first, the “½ bit” from the binary representation of (the bit representing ; if ; or equivalently, ); and second, a “sticky bit” that is 1 if any bits beyond the ½ bit were 1.

These are all equivalent definitions, using the convention that a boolean condition is 1 for true, 0 for false:

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 research!rsc

Floating-Point Printing and Parsing Can Be Simple And Fast

AI 摘要This article presents fast floating-point printing and parsing algorithms built on a new primitive called fast unrounded scaling, which approximates scaling by powers of ten, often in a single 64-bit multiplication. These simple algorithms reportedly outperform all prior known methods, including Dragon4, Grisu3, Ryū, Schubfach, and Dragonbox, and the author plans to include a Go implementation in Go 1.27. The post walks through the necessary concepts (fixed-point and floating-point numbers, unrounded numbers) and outlines implementations for fixed-width and shortest-width printing as well as decimal parsing.

Pulling a New Proof from Knuth’s Fixed-Point Printer

AI 摘要This article is a reply to Donald Knuth's 1989 paper on proving the correctness of a program that converts 16-bit fixed-point binary fractions to their shortest accurate decimal representations, written in honor of Knuth's 88th birthday. The author presents what they argue is a better proof of Knuth's program P2 by starting with a simpler program that has a trivial direct correctness proof—implemented in the APL-like Ivy language—and then transforming it into P2 step by step, proving each transformation correct. The post also explores alternative solutions and concludes with reflections on how language and notation shape programs and proofs.

Floating Point Formatting

AI 摘要The article introduces the 'Floating Point Formatting' blog series, which began in 2011 and continued with new posts in 2026. It lists four posts covering topics such as floating-point to decimal conversion, a proof inspired by Knuth's fixed-point printer, simple and fast floating-point printing and parsing, and a proof of fast unrounded scaling verified with Ivy.

Differential Coverage for Debugging

AI 摘要The article describes 'differential coverage', a debugging technique that compares the code coverage profile of a failing test with those of passing tests to isolate code blocks unique to the failing case. Demonstrating in Go, the author diffs two coverage profiles and views the result with go tool cover -html, successfully narrowing an injected bug down to 10 lines among over 15,000. While not foolproof (e.g., data-dependent bugs or insensitive tests can evade it), the technique is cheap to compute and can save considerable debugging time.

Hash-Based Bisect Debugging in Compilers and Runtimes

AI 摘要The article traces the history of debugging with binary search, from bisecting data (such as finding one bad punched card among a thousand) to bisecting version history, which was popularized by tools like git bisect that automatically pinpoint the commit that introduced a bug. It then introduces a new trick for debugging in a different dimension: hash-based bisecting of program locations, which selectively enables or disables subsets of program lines, call stacks, or code sequences to identify exactly which code causes a failure. Illustrated with a Go toolchain example, this technique is presented as a 'magic wand' for debugging large, opaque test failures in unfamiliar code bases, compilers, and runtimes.