Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x3::double_ failed to parse 1.D-3 #763

Open
xiaowen64 opened this issue Jun 9, 2023 · 5 comments
Open

x3::double_ failed to parse 1.D-3 #763

xiaowen64 opened this issue Jun 9, 2023 · 5 comments

Comments

@xiaowen64
Copy link

it is pretty common to have double precision floating point numbers to be written as something like 1.D-3. I believe many Fortran run-time libs does that. I traced it to x3/numeric/real_policies.hpp where a small change of below fixed it. should an option be provided to cope with this situation?

        template <typename Iterator>
        static bool
        parse_exp(Iterator& first, Iterator const& last)
        {
            if (first == last || (*first != 'e' && *first != 'E' && *first != 'd' && *first != 'D'))
                return false;
            ++first;
            return true;
        }
@Kojoley
Copy link
Collaborator

Kojoley commented Jun 9, 2023

The function you are citing is customizable via RealPolicies.

@xiaowen64
Copy link
Author

yeah, I thought about that as a work-around. Given that this notation is pretty common, actually just found out it's stipulated by Fortran Standard, it'd be more convenient to support it (and the 'Q' notation) natively.

@Kojoley
Copy link
Collaborator

Kojoley commented Jun 9, 2023

These D and Q are special in a way that they denote a type, it seems wrong to me to allow Q for x3::double_ or D for x3::float_. Anyway atof doesn't support them so I don't see a need to change the default behavior. Again, that's the situation RealPolicies are designed for.

@xiaowen64
Copy link
Author

You are right, 'D' for x3::float_ sounds odd. How about allowing 'D' for x3::double_? It sounds natural.

@Kojoley
Copy link
Collaborator

Kojoley commented Jun 9, 2023

It sounds natural.

No, it's not. It's a Fortran language syntax thing, std::atof and Spirit parsers don't support C and C++ language syntax things like 1.0f, 1.0d, 1.0f64 and etc., why Fortran's should be? Why also not support Fortran's 1.345E-10_8?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants