Skip to content

Commit f70b645

Browse files
committed
Candidate release.
1 parent bb140f0 commit f70b645

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.9)
22

3-
project(fast_float VERSION 1.0.0 LANGUAGES CXX)
3+
project(fast_float VERSION 2.0.0 LANGUAGES CXX)
44
option(FASTFLOAT_TEST "Enable tests" OFF)
55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ The library seeks to follow the C++17 (see 20.19.3.(7.1)) specification. In par
6868

6969
We support Visual Studio, macOS, Linux, freeBSD. We support big and little endian. We support 32-bit and 64-bit systems.
7070

71+
## Using commas as decimal separator
72+
73+
74+
The C++ standard stipulate that `from_chars` has to be locale-independent. In
75+
particular, the decimal separator has to be the period (`.`). However,
76+
some users still want to use the `fast_float` library with in a locale-dependent
77+
manner. Using a separate function called `from_chars_advanced`, we allow the users
78+
to pass a `parse_options` instance which contains a custom decimal separator (e.g.,
79+
the comma). You may use it as follows.
80+
81+
```C++
82+
#include "fast_float/fast_float.h"
83+
#include <iostream>
84+
85+
int main() {
86+
const std::string input = "3,1416 xyz ";
87+
double result;
88+
fast_float::parse_options options{fast_float::chars_format::general, ','};
89+
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
90+
if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
91+
std::cout << "parsed the number " << result << std::endl;
92+
return EXIT_SUCCESS;
93+
}
94+
```
95+
96+
7197
## Reference
7298

7399
- Daniel Lemire, [Number Parsing at a Gigabyte per Second](https://arxiv.org/abs/2101.11408), Software: Pratice and Experience 51 (8), 2021.

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ endfunction(fast_float_add_cpp_test)
5454

5555

5656
fast_float_add_cpp_test(example_test)
57+
fast_float_add_cpp_test(example_comma_test)
5758
fast_float_add_cpp_test(basictest)
5859

5960

tests/example_comma_test.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
#include "fast_float/fast_float.h"
3+
#include <iostream>
4+
5+
int main() {
6+
const std::string input = "3,1416 xyz ";
7+
double result;
8+
fast_float::parse_options options{fast_float::chars_format::general, ','};
9+
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
10+
if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
11+
std::cout << "parsed the number " << result << std::endl;
12+
return EXIT_SUCCESS;
13+
}

tests/example_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
const std::string input = "3.1416 xyz ";
77
double result;
88
auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result);
9-
if(answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
9+
if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
1010
std::cout << "parsed the number " << result << std::endl;
1111
return EXIT_SUCCESS;
1212
}

0 commit comments

Comments
 (0)