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.
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.
A drop-in from_chars built for performance-critical code paths.
Often 4× faster than the best competitor and many times faster than typical standard-library implementations. Sustains 1 GB/s on commodity hardware.
Returns the closest IEEE 754 float or double with round-to-nearest, ties-to-even — bit-for-bit correct.
Just drop in fast_float.h or use it via CMake, Conan, vcpkg, xmake, or Homebrew. Requires only C++11.
Does not allocate, does not throw, locale-independent. The interface mirrors C++17 std::from_chars.
Parses every standard integer type in bases 2–36, plus bool. The same fast, allocation-free interface.
UTF-8, UTF-16, and UTF-32 inputs. JSON, Fortran, and custom decimal separators via from_chars_advanced.
In C++20, parse strings at compile time with consteval — zero runtime cost.
Visual Studio, GCC, Clang, MSYS2. Linux, macOS, FreeBSD, Windows. x86-64, ARM, RISC-V, s390x. 32-bit and 64-bit.
Parsing random floating-point numbers, measured in megabytes per second (higher is better). Source: project benchmark suite on a typical x86-64 box.
cmake -B build -D FASTFLOAT_BENCHMARKS=ON
cmake --build build
./build/benchmarks/benchmark
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';
}
uint64_t value;
std::string hex = "4f0cedc95a718c";
auto r = fast_float::from_chars(hex.data(), hex.data() + hex.size(), value, 16);
// value == 22250738585072012
std::u16string input = u"3.1416 xyz ";
double result;
auto r = fast_float::from_chars(input.data(), input.data() + input.size(), result);
// "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};
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
Pick the workflow that matches your project.
FetchContentFetchContent_Declare(
fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
GIT_TAG tags/v8.2.5
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(fast_float)
target_link_libraries(myprogram PUBLIC fast_float)
CPMAddPackage(
NAME fast_float
GITHUB_REPOSITORY "fastfloat/fast_float"
GIT_TAG v8.2.5)
Download a pre-amalgamated header — no build system required.
curl -LO https://github.com/fastfloat/fast_float/releases/download/v8.2.5/fast_float.h
brew install fast_floatdnf install fast_float-develfast_float ships inside compilers, browsers, databases, and more.
std::from_chars since version 12