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

CleanUnitString breaks on 0.2 and 0.3 #187

Closed
Gra-tak opened this issue Oct 5, 2021 · 1 comment · Fixed by #188
Closed

CleanUnitString breaks on 0.2 and 0.3 #187

Gra-tak opened this issue Oct 5, 2021 · 1 comment · Fixed by #188

Comments

@Gra-tak
Copy link

Gra-tak commented Oct 5, 2021

Pretty weird error and I can't fully tell what the intention in this section of code is, but

units::measurement_from_string("0.2") currently yields zero.

The reason is in the following lines in units.cpp. I don't know why 2 and 3 are a special case here, but I assume there is a case '.': missing in front of the break?

        auto eit = unit_string.end() - 1;
        if (*(eit) == '2' || *(eit) == '3') {
            if ((*(eit - 1) == '-' || *(eit - 1) == '+') &&
                unit_string.size() >= 3) {
                --eit;
            }
            if (!isDigitCharacter(*(eit - 1))) {
                switch (*(eit - 1)) {
                    case '^':
                    case 'e':
                    case 'E':
                    case '/':
                    case '+':
                    case '-':
                        break;
                    case '*':
                        *(eit - 1) = '^';
                        break;
                    default:
                        if (eit[0] != '+') {
                            unit_string.insert(eit, '^');
                        } else {
                            *eit = '^';
                        }

                        break;
                }
            }
        }
    }```
@phlptp
Copy link
Collaborator

phlptp commented Oct 26, 2021

Been on vacation for a couple weeks. Thanks for this It will be fixed shortly. The intention of that section of the code is to catch things like m3 which is often used for meter^3. Missed the edge cases of numerical values ending in .3 or .2

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

Successfully merging a pull request may close this issue.

2 participants