All Projects → aclex → floaxie

aclex / floaxie

Licence: Apache-2.0 license
Floating point printing and parsing library based on Grisu2 and Krosh algorithms

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to floaxie

Graphql Go Tools
Tools to write high performance GraphQL applications using Go/Golang.
Stars: ✭ 96 (+242.86%)
Mutual labels:  parsing, printing
rita-dsl
A Domain Specific Language (DSL) for building language patterns. These can be later compiled into spaCy patterns, pure regex, or any other format
Stars: ✭ 60 (+114.29%)
Mutual labels:  parsing
BibleUtilities
Set of utilities to scan, parse, and work with Bible references.
Stars: ✭ 20 (-28.57%)
Mutual labels:  parsing
JagTag
📝 JagTag is a simple - yet powerful and customizable - interpretted text parsing language!
Stars: ✭ 40 (+42.86%)
Mutual labels:  parsing
MathExpressions.NET
➗ Library for parsing math expressions with rational numbers, finding their derivatives and compiling an optimal IL code
Stars: ✭ 63 (+125%)
Mutual labels:  parsing
pyrser
A PEG Parsing Tool
Stars: ✭ 32 (+14.29%)
Mutual labels:  parsing
Fashion-Clothing-Parsing
FCN, U-Net models implementation in TensorFlow for fashion clothing parsing
Stars: ✭ 29 (+3.57%)
Mutual labels:  parsing
cmake-reflection-template
A template for simple C++ reflection done with CMake and Python (no other external tools)
Stars: ✭ 37 (+32.14%)
Mutual labels:  parsing
shellmath
Yes, Virginia, you can do floating-point arithmetic in Bash!
Stars: ✭ 33 (+17.86%)
Mutual labels:  floating-point
BencodeNET
.NET library for encoding/decoding bencode and reading/writing torrent files
Stars: ✭ 133 (+375%)
Mutual labels:  parsing
parson
Yet another PEG parser combinator library and DSL
Stars: ✭ 52 (+85.71%)
Mutual labels:  parsing
DrawRacket4Me
DrawRacket4Me draws trees and graphs from your code, making it easier to check if the structure is what you wanted.
Stars: ✭ 43 (+53.57%)
Mutual labels:  parsing
tdop.github.io
Reprinting Vaughan Pratt's Paper on Top Down Operator Precedence Parsing
Stars: ✭ 99 (+253.57%)
Mutual labels:  parsing
yaml.sh
Read YAML files with only Bash
Stars: ✭ 30 (+7.14%)
Mutual labels:  parsing
abnf parsec
ABNF in, parser out
Stars: ✭ 42 (+50%)
Mutual labels:  parsing
herbie
Optimize floating-point expressions for accuracy
Stars: ✭ 614 (+2092.86%)
Mutual labels:  floating-point
ltreesitter
Standalone tree sitter bindings for the Lua language
Stars: ✭ 62 (+121.43%)
Mutual labels:  parsing
SteamLicenseParser
📦 Parsers your Steam licenses and generates some stats
Stars: ✭ 23 (-17.86%)
Mutual labels:  parsing
sexp-grammar
Invertible parsing for S-expressions
Stars: ✭ 28 (+0%)
Mutual labels:  parsing
python3-mal
Python interface to MyAnimeList
Stars: ✭ 18 (-35.71%)
Mutual labels:  parsing

floaxie

Build Status in GCC/Clang Build status in Visual Studio Code coverage

Floaxie is C++14 header-only library for fast printing floating point values of arbitrary precision (float, double etc.) and parsing their textual representation back again (in ordinary or exponent notation).

What is it for?

One is obviously not worried too much about the speed of the values being printed on the console, so the primary places to use the library are readers, writers, encoders and decoders of different text-based formats (e.g. JSON, XML and so on), applications interacting through text pipes or rendering data structures.

Please, take a look also at the alternatives solving the same problem mentioned in the benchmark of @miloyip here, if floaxie doesn't suite you well.

Compiler compatibility

  • GCC 5
  • Clang 3.6
  • Visual Studio 2017 15.0

Printing

Grisu2 algorithm is adopted for printing floating point values. It is fast printing algorithm described by Florian Loitsch in his Printing Floating-Point Numbers Quickly and Accurately with Integers paper. Grisu2 is chosen as probably the fastest grisu version, for cases, where shortest possible representation in 100% of cases is not ultimately important. Still it guarantees the best possible efficiency of more, than 99%.

Parsing

The opposite to Grisu algorithm used for printing, an algorithm on the same theoretical base, but for parsing, is developed. Following the analogue of Grisu naming, who essentially appears to be cartoon character (Dragon), parsing algorithm is named after another animated character, rabbit, Krosh: Krosh

The algorithm parses decimal mantissa to extent of slightly more decimal digit capacity of floating point types, chooses a pre-calculated decimal power and then multiplies the two. Since the rounding problem is not uncommon during such operations, and, in contrast to printing problem, one can't just return incorrectly rounded parsing results, such cases are detected instead and slower, but accurate fallback conversion is performed (C Standard Library functions like strtod() by default). In this respect Krosh is closer to Grisu3.

Example

Printing:

#include <iostream>

#include "floaxie/ftoa.h"

using namespace std;
using namespace floaxie;

int main(int, char**)
{
	double pi = 0.1;
	char buffer[128];

	ftoa(pi, buffer);
	cout << "pi: " << pi << ", buffer: " << buffer << endl;

	return 0;
}

Parsing:

#include <iostream>

#include "floaxie/atof.h"

using namespace std;
using namespace floaxie;

int main(int, char**)
{
	char str[] = "0.1";
	char* str_end;
	double pi = 0;

	pi = atof<double>(str, &str_end);
	cout << "pi: " << pi << ", str: " << str << ", str_end: " << str_end << endl;

	return 0;
}

Building

Building is not required and completely optional, unless you would like to try the examples or tests or build the local documentation. Inside git project tree it can be done like this:

git submodule update --init # to check out common CMake modules' submodule
mkdir build && cd build
cmake -DBUILD_EXAMPLES=1 -DBUILD_TESTS=1 -DBUILD_DOCUMENTATION=1 ../ # switch on the desired flags
cmake --build . # or just `make` on systems with it

Adding to the project

git submodule add https://github.com/aclex/floaxie <desired-path-in-your-project>

Don't forget to do git submodule update --init --recursive out of your project tree to pull submodules properly.

Including to CMake project as a subproject

Since version 1.2 it's possible to include Floaxie as a subproject in any CMake project quite easily thanks to modern CMake INTERFACE_LIBRARY target facilities. Unfortunately, this works fully since CMake 3.13, so its minimum required version had to be increased.

CMakeLists.txt of a consumer CMake project would look like this (given Floaxie is cloned to floaxie subdirectory)':

project(foo)

cmake_minimum_required(VERSION 3.13)

# `EXCLUDE_FOR_ALL` here to exclude supplementary targets
# like `install` from the main project target set
add_subdirectory(peli EXCLUDE_FROM_ALL) 

add_executable(foo_main foo_main.cpp)
target_link_libraries(foo_main PUBLIC floaxie)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].