Schubfach

December 9, 2025 ยท View on GitHub

A C++ implementation of the Schubfach algorithm - fast and accurate conversion of IEEE-754 double values to decimal strings.

For a faster method see https://github.com/vitaut/zmij.

Usage:

#include "schubfach.h"
#include <stdio.h>

int main() {
  char buf[schubfach::buffer_size];
  schubfach::dtoa(6.62607015e-34, buf);
  puts(buf);
}

Average formatting time from dtoa-benchmark, smaller is better:

image

FunctionTime (ns)Speedup
ostringstream880.2451.00x
sprintf742.6541.19x
doubleconv83.62910.53x
ryu37.18423.67x
schubfach24.86535.40x
fmt22.33139.42x
dragonbox20.78242.36x

The binary size is ~12kiB on an ARM-based macOS:

% c++ -c -Os -DNDEBUG -std=c++20 schubfach.cc
% du -Ah schubfach.o
 12K	schubfach.o

Build time is ~77ms by default and ~95ms with optimizations enabled as measured by

% time c++ -c -std=c++20 schubfach.cc [-O2]

taking the best of 3 runs.