Skip to content
forked from vitaut/zmij

A double-to-string conversion algorithm based on Schubfach and yy

License

Notifications You must be signed in to change notification settings

dtolnay-contrib/zmij-c

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

151 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Żmij

A double-to-string conversion algorithm based on Schubfach and yy with implementations in C and C++

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 871.982 1.00x
sprintf 737.510 1.18x
double-conversion 84.304 10.34x
to_chars 42.786 20.38x
ryu 37.081 23.52x
schubfach 24.885 35.04x
fmt 22.274 39.15x
dragonbox 20.701 42.12x
yy 13.974 62.40x
zmij 12.271 71.06x
null 0.930 937.62x
image image

Compile time

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

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

taking the best of 3 runs.

Other languages

Differences from Schubfach

  • 1 instead of 3 multiplications by powers of 10 in the common case
  • Faster logarithm approximations
  • Faster division and modulo
  • Fewer conditional branches
  • More efficient significand and exponent output
  • Improved storage of powers of 10

Name

Żmij (pronounced roughly zhmeey or more precisely /ʐmij/) is a Polish word that refers to a mythical dragon- or serpent-like creature. This continues the dragon theme started by Steele and White. Nice feature of this name is that it has a floating point in the first letter.

About

A double-to-string conversion algorithm based on Schubfach and yy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.9%
  • C 2.9%
  • Other 0.2%