Skip to content
C++11 · header-only · triple-licensed

# Parse floating-point numbers at a gigabyte per second.

fast_float is a header-only C++ implementation of `std::from_chars` for `float`, `double`, and integer types. Exact IEEE rounding, no allocations, no exceptions — often many times faster than your standard library.

Get started View on GitHub Download `v{{VERSION}}`
Latest release: `v{{VERSION}}` Apache 2.0 MIT Boost

## Why fast_float?

A drop-in `from_chars` built for performance-critical code paths.

### Blazing fast

Often 4× faster than the best competitor and many times faster than typical standard-library implementations. Sustains 1 GB/s on commodity hardware.

### Exact rounding

Returns the closest IEEE 754 `float` or `double` with round-to-nearest, ties-to-even — bit-for-bit correct.

### Header-only

Just drop in `fast_float.h` or use it via CMake, Conan, vcpkg, xmake, or Homebrew. Requires only C++11.

### No surprises

Does not allocate, does not throw, locale-independent. The interface mirrors C++17 `std::from_chars`.

### Integers too

Parses every standard integer type in bases 2–36, plus `bool`. The same fast, allocation-free interface.

### Unicode & formats

UTF-8, UTF-16, and UTF-32 inputs. JSON, Fortran, and custom decimal separators via `from_chars_advanced`.

### constexpr-ready

In C++20, parse strings at compile time with `consteval` — zero runtime cost.

### Portable

Visual Studio, GCC, Clang, MSYS2. Linux, macOS, FreeBSD, Windows. x86-64, ARM, RISC-V, s390x. 32-bit and 64-bit.

## Performance

Parsing random floating-point numbers, measured in megabytes per second (higher is better). Source: project benchmark suite on a typical x86-64 box.

fast_float
1042 MB/s
abseil
430 MB/s
netlib
271 MB/s
double-conversion
225 MB/s
strtod
191 MB/s
Reproduce these numbers

    cmake -B build -D FASTFLOAT_BENCHMARKS=ON
    cmake --build build
    ./build/benchmarks/benchmark

## Quick start

Parse a `double` from a string in three lines.

    #include "fast_float/fast_float.h"
    #include <iostream>
    #include <string>

    int main() {
      std::string input = "3.1416 xyz ";
      double result;
      auto answer = fast_float::from_chars(input.data(),
                                           input.data() + input.size(),
                                           result);
      if (answer.ec != std::errc()) {
        std::cerr << "parsing failure\n";
        return EXIT_FAILURE;
      }
      std::cout << "parsed the number " << result << '\n';
    }

### Integers in any base (2–36)

    uint64_t value;
    std::string hex = "4f0cedc95a718c";
    auto r = fast_float::from_chars(hex.data(), hex.data() + hex.size(), value, 16);
    // value == 22250738585072012

### UTF-16 input

    std::u16string input = u"3.1416 xyz ";
    double result;
    auto r = fast_float::from_chars(input.data(), input.data() + input.size(), result);

### Comma as decimal separator, Fortran, or JSON

    // "3,1416" — French-style
    fast_float::parse_options opts{fast_float::chars_format::general, ','};
    fast_float::from_chars_advanced(s.data(), s.data() + s.size(), result, opts);

    // "1d+4" — Fortran exponent
    opts = {fast_float::chars_format::fortran};

    // strict JSON per RFC 8259
    opts = {fast_float::chars_format::json};

### C++20: parse at compile time

    consteval double parse(std::string_view s) {
      double v;
      auto r = fast_float::from_chars(s.data(), s.data() + s.size(), v);
      return r.ec == std::errc() ? v : -1.0;
    }
    constexpr double pi = parse("3.1415");  // computed at compile time

## Install

Pick the workflow that matches your project.

### CMake `FetchContent`

    FetchContent_Declare(
      fast_float
      GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
      GIT_TAG tags/v{{VERSION}}
      GIT_SHALLOW TRUE)
    FetchContent_MakeAvailable(fast_float)
    target_link_libraries(myprogram PUBLIC fast_float)

### CPM

    CPMAddPackage(
      NAME fast_float
      GITHUB_REPOSITORY "fastfloat/fast_float"
      GIT_TAG v{{VERSION}})

### Single header

Download a pre-amalgamated header — no build system required.

    curl -LO https://github.com/fastfloat/fast_float/releases/download/v{{VERSION}}/fast_float.h

### Package managers

- Conan
- Homebrew — `brew install fast_float`
- xmake
- Fedora — `dnf install fast_float-devel`
- More distributions

## Trusted by

fast_float ships inside compilers, browsers, databases, and more.

- GCC — backs `std::from_chars` since version 12
- Chromium — Chrome, Edge, and Opera
- WebKit — Safari
- Ladybird — independent browser engine
- DuckDB — in-process analytical database
- Apache Arrow — 2–3× faster number parsing
- ClickHouse — OLAP database
- MySQL
- Boost.JSON
- Blender
- Google Jsonnet

Ports and bindings exist for Rust, Java, C#, C, and R.

## The research behind it

- Daniel Lemire, Number Parsing at a Gigabyte per Second. Software: Practice and Experience 51(8), 2021.
- Noble Mushtak, Daniel Lemire, Fast Number Parsing Without Fallback. Software: Practice and Experience 53(7), 2023.