Skip to content

integer wrap-around in src/Ch03/03_09/CodeDemo.cpp #3

@02de16e2

Description

@02de16e2

Calling the example solution with a = -3, b = 0 and c = 0 yields 1431655764.3333 instead of -1.

This is because the addition is in uint32_t and wraps around.

Since the example solution is apparently used as reference for checking user solutions, correct implementations are rejected:

Something isn't working. 
Your code returned: -1
--- -- -- -- -- -- -- -- -- -- -- --
Need Help?
* Expected result: 1431655764.3333

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions