Skip to content

TobiSchluter/zmij

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Żmij

A double-to-string conversion algorithm based on Schubfach

Features

Usage

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

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

Performance

More than 3x faster than Ryu used by multiple C++ standard library implementations and ~2x faster than Schubfach on dtoa-benchmark run on Apple M1.

Function Time (ns) Speedup
ostringstream 902.796 1.00x
sprintf 737.769 1.22x
doubleconv 85.790 10.52x
to_chars 42.779 21.10x
ryu 38.631 23.37x
schubfach 25.292 35.69x
fmt 22.384 40.33x
dragonbox 21.162 42.66x
zmij 12.360 73.04x
null 0.957 943.30x

image

image

Compile time

Compile time is ~60ms by default and ~68ms with optimizations enabled as measured by

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

taking the best of 3 runs.

Differences from Schubfach

  • Selection from 1-3 candidates instead of 2-4
  • Fewer integer multiplications in the shorter case
  • Faster logarithm approximations
  • Faster division and modulo
  • Fewer conditional branches
  • More efficient significand and exponent output

About

A double-to-string conversion algorithm based on Schubfach

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 99.8%
  • Other 0.2%