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

Floating point exception #35

Closed
oceanofthelost opened this issue Jan 15, 2023 · 2 comments
Closed

Floating point exception #35

oceanofthelost opened this issue Jan 15, 2023 · 2 comments
Assignees

Comments

@oceanofthelost
Copy link
Contributor

System

Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy

Error

A divide by zero error can occur when providing rounding:

case token_round_down:
        token_next();
        multiple = get_number("-round-down");
        if(multiple == 0)
        {
            multiple = 1;
        }
        value /= multiple;
        value *= multiple;
        cout<<"HERE"<<endl;
        break;

    case token_round_up:
        token_next();
        multiple = get_number("-round-up");
        value = (value + multiple - 1) / multiple;
        value *= multiple;
        break;

    case token_round_nearest:
        token_next();
        multiple = get_number("-round-nearest");
        value = (value + multiple / 2) / multiple;
        value *= multiple;
        break;

When providing the following as input:

$ srec_cat test.in  -offset  - 1 -Round_Up 0
$ srec_cat test.in  -offset  - 1 -Round_Down 0
$ srec_cat test.in  -offset  - 1 -Round_Nearest 0

In each of the above cases, output will be

Floating point exception (core dumped)

Issue is due to line

multiple = get_number("-round-up");

which is not verified to be non zero. In each of the above cases, immediately following parsing 0, 0 will be used and cause an exception.

@jtxa
Copy link
Contributor

jtxa commented Jan 16, 2023

That's a nice catch and fix.

I was confused by the - 1, so needed to read the manual and play around a bit. It seems that those calculations can only be applied to other calculated values, not simple numbers.
So an -offset 7 -Round_Up 4 has to be written as -offset - -7 -Round_Up 4

@SeanAlling-DojoFive
Copy link
Contributor

With #36 merged I think we can close this bug.

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

3 participants