compilation fixes.

This commit is contained in:
IRainman 2025-05-06 21:05:05 +03:00
parent f2befa5876
commit e5f189754f
5 changed files with 53 additions and 63 deletions

View File

@ -75,22 +75,21 @@ template <typename UC> struct from_chars_result_t {
using from_chars_result = from_chars_result_t<char>;
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_t const b = 10) noexcept
: format(fmt), decimal_point(dot),
base(b){
: format(fmt), decimal_point(dot), base(b) {
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
// static_assert(b >= 2 && b <= 36);
// static_assert(b >= 2 && b <= 36);
#endif
}
}
/** Which number formats are accepted */
chars_format const format;
/** Which number formats are accepted */
chars_format format;
/** The character used as decimal point */
UC const decimal_point;
UC decimal_point;
/** 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);
};

View File

@ -644,20 +644,19 @@ TEST_CASE("check_behavior") {
TEST_CASE("decimal_point_parsing") {
double result;
fast_float::parse_options options{};
{
std::string const input = "1,25";
auto answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result,
fast_float::parse_options{});
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + 1,
"Parsing should have stopped at comma");
CHECK_EQ(result, 1.0);
options.decimal_point = ',';
answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result,
fast_float::parse_options(
{fast_float::chars_format::general, ',', 10}));
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
"Parsing should have stopped at end");
@ -666,17 +665,15 @@ TEST_CASE("decimal_point_parsing") {
{
std::string const input = "1.25";
auto answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result,
fast_float::parse_options(
{fast_float::chars_format::general, ',', 10}));
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + 1,
"Parsing should have stopped at dot");
CHECK_EQ(result, 1.0);
options.decimal_point = '.';
answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result,
fast_float::parse_options{});
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
"Parsing should have stopped at end");
@ -1325,8 +1322,9 @@ TEST_CASE("double.general") {
TEST_CASE("double.decimal_point") {
constexpr auto options = [] {
return fast_float::parse_options(
{fast_float::chars_format::general, ',', 10});
fast_float::parse_options ret{};
ret.decimal_point = ',';
return ret;
}();
// infinities
@ -1643,8 +1641,9 @@ TEST_CASE("float.general") {
TEST_CASE("float.decimal_point") {
constexpr auto options = [] {
return fast_float::parse_options(
{fast_float::chars_format::general, ',', 10});
fast_float::parse_options ret{};
ret.decimal_point = ',';
return ret;
}();
// infinity

View File

@ -7,9 +7,9 @@
int main() {
std::string const 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,
fast_float::parse_options({fast_float::chars_format::general, ','}));
input.data(), input.data() + input.size(), result, options);
if ((answer.ec != std::errc()) || ((result != 3.1416))) {
std::cerr << "parsing failure\n";
return EXIT_FAILURE;

View File

@ -9,11 +9,11 @@
int main_readme() {
std::string const input = "1d+4";
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(
input.data(), input.data() + input.size(), result,
fast_float::parse_options(
{fast_float::chars_format::fortran |
fast_float::chars_format::allow_leading_plus}));
input.data(), input.data() + input.size(), result, options);
if ((answer.ec != std::errc()) || ((result != 10000))) {
std::cerr << "parsing failure\n" << result << "\n";
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",
"+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) {
auto d{std::distance(&fmt1[0], &f)};
double result;
auto answer{fast_float::from_chars_advanced(
f.data(), f.data() + f.size(), result,
fast_float::parse_options(
{fast_float::chars_format::fortran |
fast_float::chars_format::allow_leading_plus}))};
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
result, options)};
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
std::cerr << "parsing failure on " << f << std::endl;
return EXIT_FAILURE;
@ -49,11 +50,8 @@ int main() {
for (auto const &f : fmt2) {
auto d{std::distance(&fmt2[0], &f)};
double result;
auto answer{fast_float::from_chars_advanced(
f.data(), f.data() + f.size(), result,
fast_float::parse_options(
{fast_float::chars_format::fortran |
fast_float::chars_format::allow_leading_plus}))};
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
result, options)};
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
std::cerr << "parsing failure on " << f << std::endl;
return EXIT_FAILURE;
@ -63,11 +61,8 @@ int main() {
for (auto const &f : fmt3) {
auto d{std::distance(&fmt3[0], &f)};
double result;
auto answer{fast_float::from_chars_advanced(
f.data(), f.data() + f.size(), result,
fast_float::parse_options(
{fast_float::chars_format::fortran |
fast_float::chars_format::allow_leading_plus}))};
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
result, options)};
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
std::cerr << "parsing failure on " << f << std::endl;
return EXIT_FAILURE;

View File

@ -7,12 +7,11 @@
int main_readme() {
std::string const input = "+.1"; // not valid
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(
input.data(), input.data() + input.size(), result,
fast_float::parse_options options(
{fast_float::chars_format::json |
fast_float::chars_format::allow_leading_plus}) // should be ignored
);
input.data(), input.data() + input.size(), result, options);
if (answer.ec == std::errc()) {
std::cerr << "should have failed\n";
return EXIT_FAILURE;
@ -23,12 +22,11 @@ int main_readme() {
int main_readme2() {
std::string const input = "inf"; // not valid in JSON
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(
input.data(), input.data() + input.size(), result,
fast_float::parse_options options(
{fast_float::chars_format::json |
fast_float::chars_format::allow_leading_plus}) // should be ignored
);
input.data(), input.data() + input.size(), result, options);
if (answer.ec == std::errc()) {
std::cerr << "should have failed\n";
return EXIT_FAILURE;
@ -40,12 +38,11 @@ int main_readme3() {
std::string const input =
"inf"; // not valid in JSON but we allow it with json_or_infnan
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(
input.data(), input.data() + input.size(), result,
fast_float::parse_options options(
{fast_float::chars_format::json_or_infnan |
fast_float::chars_format::allow_leading_plus}); // should be ignored
);
input.data(), input.data() + input.size(), result, options);
if (answer.ec != std::errc() || (!std::isinf(result))) {
std::cerr << "should have parsed infinity\n";
return EXIT_FAILURE;
@ -137,9 +134,9 @@ int main() {
auto answer = fast_float::parse_number_string<true>(
f.data(), f.data() + f.size(),
fast_float::parse_options(
{fast_float::chars_format::json |
fast_float::chars_format::allow_leading_plus})); // should be
// ignored
fast_float::chars_format::json |
fast_float::chars_format::allow_leading_plus)); // should be
// ignored
if (answer.valid) {
std::cerr << "json parse accepted invalid json " << f << std::endl;
return EXIT_FAILURE;
@ -171,4 +168,4 @@ int main() {
#endif
return EXIT_SUCCESS;
}
}