mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
compilation fixes.
This commit is contained in:
parent
f2befa5876
commit
e5f189754f
@ -75,22 +75,21 @@ template <typename UC> struct from_chars_result_t {
|
|||||||
using from_chars_result = from_chars_result_t<char>;
|
using from_chars_result = from_chars_result_t<char>;
|
||||||
|
|
||||||
template <typename UC> struct parse_options_t {
|
template <typename UC> struct parse_options_t {
|
||||||
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
|
constexpr explicit parse_options_t(
|
||||||
chars_format const fmt = chars_format::general, UC const dot = UC('.'),
|
chars_format const fmt = chars_format::general, UC const dot = UC('.'),
|
||||||
chars_format_t const b = 10) noexcept
|
chars_format_t const b = 10) noexcept
|
||||||
: format(fmt), decimal_point(dot),
|
: format(fmt), decimal_point(dot), base(b) {
|
||||||
base(b){
|
|
||||||
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
// static_assert(b >= 2 && b <= 36);
|
// static_assert(b >= 2 && b <= 36);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Which number formats are accepted */
|
/** Which number formats are accepted */
|
||||||
chars_format const format;
|
chars_format format;
|
||||||
/** The character used as decimal point */
|
/** The character used as decimal point */
|
||||||
UC const decimal_point;
|
UC decimal_point;
|
||||||
/** The base used for integers */
|
/** The base used for integers */
|
||||||
uint_fast8_t const base; /* only allowed from 2 to 36 */
|
uint_fast8_t base; /* only allowed from 2 to 36 */
|
||||||
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -644,20 +644,19 @@ TEST_CASE("check_behavior") {
|
|||||||
|
|
||||||
TEST_CASE("decimal_point_parsing") {
|
TEST_CASE("decimal_point_parsing") {
|
||||||
double result;
|
double result;
|
||||||
|
fast_float::parse_options options{};
|
||||||
{
|
{
|
||||||
std::string const input = "1,25";
|
std::string const input = "1,25";
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options{});
|
|
||||||
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
CHECK_MESSAGE(answer.ptr == input.data() + 1,
|
CHECK_MESSAGE(answer.ptr == input.data() + 1,
|
||||||
"Parsing should have stopped at comma");
|
"Parsing should have stopped at comma");
|
||||||
CHECK_EQ(result, 1.0);
|
CHECK_EQ(result, 1.0);
|
||||||
|
|
||||||
|
options.decimal_point = ',';
|
||||||
answer = fast_float::from_chars_advanced(
|
answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options(
|
|
||||||
{fast_float::chars_format::general, ',', 10}));
|
|
||||||
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
|
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
|
||||||
"Parsing should have stopped at end");
|
"Parsing should have stopped at end");
|
||||||
@ -666,17 +665,15 @@ TEST_CASE("decimal_point_parsing") {
|
|||||||
{
|
{
|
||||||
std::string const input = "1.25";
|
std::string const input = "1.25";
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options(
|
|
||||||
{fast_float::chars_format::general, ',', 10}));
|
|
||||||
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
CHECK_MESSAGE(answer.ptr == input.data() + 1,
|
CHECK_MESSAGE(answer.ptr == input.data() + 1,
|
||||||
"Parsing should have stopped at dot");
|
"Parsing should have stopped at dot");
|
||||||
CHECK_EQ(result, 1.0);
|
CHECK_EQ(result, 1.0);
|
||||||
|
|
||||||
|
options.decimal_point = '.';
|
||||||
answer = fast_float::from_chars_advanced(
|
answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options{});
|
|
||||||
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
|
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
|
||||||
"Parsing should have stopped at end");
|
"Parsing should have stopped at end");
|
||||||
@ -1325,8 +1322,9 @@ TEST_CASE("double.general") {
|
|||||||
|
|
||||||
TEST_CASE("double.decimal_point") {
|
TEST_CASE("double.decimal_point") {
|
||||||
constexpr auto options = [] {
|
constexpr auto options = [] {
|
||||||
return fast_float::parse_options(
|
fast_float::parse_options ret{};
|
||||||
{fast_float::chars_format::general, ',', 10});
|
ret.decimal_point = ',';
|
||||||
|
return ret;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
// infinities
|
// infinities
|
||||||
@ -1643,8 +1641,9 @@ TEST_CASE("float.general") {
|
|||||||
|
|
||||||
TEST_CASE("float.decimal_point") {
|
TEST_CASE("float.decimal_point") {
|
||||||
constexpr auto options = [] {
|
constexpr auto options = [] {
|
||||||
return fast_float::parse_options(
|
fast_float::parse_options ret{};
|
||||||
{fast_float::chars_format::general, ',', 10});
|
ret.decimal_point = ',';
|
||||||
|
return ret;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
// infinity
|
// infinity
|
||||||
|
|||||||
@ -7,9 +7,9 @@
|
|||||||
int main() {
|
int main() {
|
||||||
std::string const input = "3,1416 xyz ";
|
std::string const input = "3,1416 xyz ";
|
||||||
double result;
|
double result;
|
||||||
|
fast_float::parse_options options{fast_float::chars_format::general, ','};
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options({fast_float::chars_format::general, ','}));
|
|
||||||
if ((answer.ec != std::errc()) || ((result != 3.1416))) {
|
if ((answer.ec != std::errc()) || ((result != 3.1416))) {
|
||||||
std::cerr << "parsing failure\n";
|
std::cerr << "parsing failure\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
int main_readme() {
|
int main_readme() {
|
||||||
std::string const input = "1d+4";
|
std::string const input = "1d+4";
|
||||||
double result;
|
double result;
|
||||||
|
fast_float::parse_options options{
|
||||||
|
fast_float::chars_format::fortran |
|
||||||
|
fast_float::chars_format::allow_leading_plus};
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options(
|
|
||||||
{fast_float::chars_format::fortran |
|
|
||||||
fast_float::chars_format::allow_leading_plus}));
|
|
||||||
if ((answer.ec != std::errc()) || ((result != 10000))) {
|
if ((answer.ec != std::errc()) || ((result != 10000))) {
|
||||||
std::cerr << "parsing failure\n" << result << "\n";
|
std::cerr << "parsing failure\n" << result << "\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -32,14 +32,15 @@ int main() {
|
|||||||
std::vector<std::string> const fmt3{"+1+4", "+1+3", "+1+2", "+1+1", "+1+0",
|
std::vector<std::string> const fmt3{"+1+4", "+1+3", "+1+2", "+1+1", "+1+0",
|
||||||
"+1-1", "+1-2", "+1-3", "+1-4"};
|
"+1-1", "+1-2", "+1-3", "+1-4"};
|
||||||
|
|
||||||
|
fast_float::parse_options const options{
|
||||||
|
fast_float::chars_format::fortran |
|
||||||
|
fast_float::chars_format::allow_leading_plus};
|
||||||
|
|
||||||
for (auto const &f : fmt1) {
|
for (auto const &f : fmt1) {
|
||||||
auto d{std::distance(&fmt1[0], &f)};
|
auto d{std::distance(&fmt1[0], &f)};
|
||||||
double result;
|
double result;
|
||||||
auto answer{fast_float::from_chars_advanced(
|
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
||||||
f.data(), f.data() + f.size(), result,
|
result, options)};
|
||||||
fast_float::parse_options(
|
|
||||||
{fast_float::chars_format::fortran |
|
|
||||||
fast_float::chars_format::allow_leading_plus}))};
|
|
||||||
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
||||||
std::cerr << "parsing failure on " << f << std::endl;
|
std::cerr << "parsing failure on " << f << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -49,11 +50,8 @@ int main() {
|
|||||||
for (auto const &f : fmt2) {
|
for (auto const &f : fmt2) {
|
||||||
auto d{std::distance(&fmt2[0], &f)};
|
auto d{std::distance(&fmt2[0], &f)};
|
||||||
double result;
|
double result;
|
||||||
auto answer{fast_float::from_chars_advanced(
|
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
||||||
f.data(), f.data() + f.size(), result,
|
result, options)};
|
||||||
fast_float::parse_options(
|
|
||||||
{fast_float::chars_format::fortran |
|
|
||||||
fast_float::chars_format::allow_leading_plus}))};
|
|
||||||
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
||||||
std::cerr << "parsing failure on " << f << std::endl;
|
std::cerr << "parsing failure on " << f << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -63,11 +61,8 @@ int main() {
|
|||||||
for (auto const &f : fmt3) {
|
for (auto const &f : fmt3) {
|
||||||
auto d{std::distance(&fmt3[0], &f)};
|
auto d{std::distance(&fmt3[0], &f)};
|
||||||
double result;
|
double result;
|
||||||
auto answer{fast_float::from_chars_advanced(
|
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
||||||
f.data(), f.data() + f.size(), result,
|
result, options)};
|
||||||
fast_float::parse_options(
|
|
||||||
{fast_float::chars_format::fortran |
|
|
||||||
fast_float::chars_format::allow_leading_plus}))};
|
|
||||||
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
||||||
std::cerr << "parsing failure on " << f << std::endl;
|
std::cerr << "parsing failure on " << f << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
@ -7,12 +7,11 @@
|
|||||||
int main_readme() {
|
int main_readme() {
|
||||||
std::string const input = "+.1"; // not valid
|
std::string const input = "+.1"; // not valid
|
||||||
double result;
|
double result;
|
||||||
|
fast_float::parse_options options{
|
||||||
|
fast_float::chars_format::json |
|
||||||
|
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options options(
|
|
||||||
{fast_float::chars_format::json |
|
|
||||||
fast_float::chars_format::allow_leading_plus}) // should be ignored
|
|
||||||
);
|
|
||||||
if (answer.ec == std::errc()) {
|
if (answer.ec == std::errc()) {
|
||||||
std::cerr << "should have failed\n";
|
std::cerr << "should have failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -23,12 +22,11 @@ int main_readme() {
|
|||||||
int main_readme2() {
|
int main_readme2() {
|
||||||
std::string const input = "inf"; // not valid in JSON
|
std::string const input = "inf"; // not valid in JSON
|
||||||
double result;
|
double result;
|
||||||
|
fast_float::parse_options options{
|
||||||
|
fast_float::chars_format::json |
|
||||||
|
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options options(
|
|
||||||
{fast_float::chars_format::json |
|
|
||||||
fast_float::chars_format::allow_leading_plus}) // should be ignored
|
|
||||||
);
|
|
||||||
if (answer.ec == std::errc()) {
|
if (answer.ec == std::errc()) {
|
||||||
std::cerr << "should have failed\n";
|
std::cerr << "should have failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -40,12 +38,11 @@ int main_readme3() {
|
|||||||
std::string const input =
|
std::string const input =
|
||||||
"inf"; // not valid in JSON but we allow it with json_or_infnan
|
"inf"; // not valid in JSON but we allow it with json_or_infnan
|
||||||
double result;
|
double result;
|
||||||
|
fast_float::parse_options options{
|
||||||
|
fast_float::chars_format::json_or_infnan |
|
||||||
|
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result,
|
input.data(), input.data() + input.size(), result, options);
|
||||||
fast_float::parse_options options(
|
|
||||||
{fast_float::chars_format::json_or_infnan |
|
|
||||||
fast_float::chars_format::allow_leading_plus}); // should be ignored
|
|
||||||
);
|
|
||||||
if (answer.ec != std::errc() || (!std::isinf(result))) {
|
if (answer.ec != std::errc() || (!std::isinf(result))) {
|
||||||
std::cerr << "should have parsed infinity\n";
|
std::cerr << "should have parsed infinity\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -137,8 +134,8 @@ int main() {
|
|||||||
auto answer = fast_float::parse_number_string<true>(
|
auto answer = fast_float::parse_number_string<true>(
|
||||||
f.data(), f.data() + f.size(),
|
f.data(), f.data() + f.size(),
|
||||||
fast_float::parse_options(
|
fast_float::parse_options(
|
||||||
{fast_float::chars_format::json |
|
fast_float::chars_format::json |
|
||||||
fast_float::chars_format::allow_leading_plus})); // should be
|
fast_float::chars_format::allow_leading_plus)); // should be
|
||||||
// ignored
|
// ignored
|
||||||
if (answer.valid) {
|
if (answer.valid) {
|
||||||
std::cerr << "json parse accepted invalid json " << f << std::endl;
|
std::cerr << "json parse accepted invalid json " << f << std::endl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user