mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 01:06:48 +08:00
Candidate release.
This commit is contained in:
parent
bb140f0a87
commit
f70b645436
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.9)
|
cmake_minimum_required(VERSION 3.9)
|
||||||
|
|
||||||
project(fast_float VERSION 1.0.0 LANGUAGES CXX)
|
project(fast_float VERSION 2.0.0 LANGUAGES CXX)
|
||||||
option(FASTFLOAT_TEST "Enable tests" OFF)
|
option(FASTFLOAT_TEST "Enable tests" OFF)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|||||||
26
README.md
26
README.md
@ -68,6 +68,32 @@ The library seeks to follow the C++17 (see 20.19.3.(7.1)) specification. In par
|
|||||||
|
|
||||||
We support Visual Studio, macOS, Linux, freeBSD. We support big and little endian. We support 32-bit and 64-bit systems.
|
We support Visual Studio, macOS, Linux, freeBSD. We support big and little endian. We support 32-bit and 64-bit systems.
|
||||||
|
|
||||||
|
## Using commas as decimal separator
|
||||||
|
|
||||||
|
|
||||||
|
The C++ standard stipulate that `from_chars` has to be locale-independent. In
|
||||||
|
particular, the decimal separator has to be the period (`.`). However,
|
||||||
|
some users still want to use the `fast_float` library with in a locale-dependent
|
||||||
|
manner. Using a separate function called `from_chars_advanced`, we allow the users
|
||||||
|
to pass a `parse_options` instance which contains a custom decimal separator (e.g.,
|
||||||
|
the comma). You may use it as follows.
|
||||||
|
|
||||||
|
```C++
|
||||||
|
#include "fast_float/fast_float.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const std::string input = "3,1416 xyz ";
|
||||||
|
double result;
|
||||||
|
fast_float::parse_options options{fast_float::chars_format::general, ','};
|
||||||
|
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
|
||||||
|
if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
|
||||||
|
std::cout << "parsed the number " << result << std::endl;
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
- Daniel Lemire, [Number Parsing at a Gigabyte per Second](https://arxiv.org/abs/2101.11408), Software: Pratice and Experience 51 (8), 2021.
|
- Daniel Lemire, [Number Parsing at a Gigabyte per Second](https://arxiv.org/abs/2101.11408), Software: Pratice and Experience 51 (8), 2021.
|
||||||
|
|||||||
@ -54,6 +54,7 @@ endfunction(fast_float_add_cpp_test)
|
|||||||
|
|
||||||
|
|
||||||
fast_float_add_cpp_test(example_test)
|
fast_float_add_cpp_test(example_test)
|
||||||
|
fast_float_add_cpp_test(example_comma_test)
|
||||||
fast_float_add_cpp_test(basictest)
|
fast_float_add_cpp_test(basictest)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
tests/example_comma_test.cpp
Normal file
13
tests/example_comma_test.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#include "fast_float/fast_float.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const std::string input = "3,1416 xyz ";
|
||||||
|
double result;
|
||||||
|
fast_float::parse_options options{fast_float::chars_format::general, ','};
|
||||||
|
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
|
||||||
|
if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
|
||||||
|
std::cout << "parsed the number " << result << std::endl;
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ int main() {
|
|||||||
const std::string input = "3.1416 xyz ";
|
const std::string input = "3.1416 xyz ";
|
||||||
double result;
|
double result;
|
||||||
auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), 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; }
|
if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
|
||||||
std::cout << "parsed the number " << result << std::endl;
|
std::cout << "parsed the number " << result << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user