Skip to content

Bug: Calculation error caused by incorrect detection of isPowerOfTen() #56

Closed
@ZCG-coder

Description

@ZCG-coder

Describe the bug

There is a calculation error caused by incorrect detection of isPowerOfTen(). isPowerOfTen() incorrectly assumes a decimal like 0.1111 to be a power of 10, while it is not. This leads to a chain of errors, specifically multiply() trying to simplify the calculation by moving decimal places, leading to a wrong result.

To Reproduce

Steps to reproduce the behavior:

  1. Run the calc_multiply program with arguments -4.4000000000, 0.11111111.
  2. Outputs 0.44, with a note showing it has done the calculation by moving decimal places.

Expected behavior

Output should be -0.488888884, and should not be done by moving decimal places.

Screenshots

$ src/calc_multiply -4.4000000000 0.111111111111
◉calc::multiply - INFO: -4.4000000000 × 0.111111111111 = -0.48888888888840000000000000000000000000000000000000
                                          4  4
×        0  1  1  1  1  1  1  1  1  1  1  1  1
_________________________________________________



         4  4  0  0  0  0  0  0  0  0  0  0  0

            4  4  0  0  0  0  0  0  0  0  0  0

               4  4  0  0  0  0  0  0  0  0  0

                  4  4  0  0  0  0  0  0  0  0

                     4  4  0  0  0  0  0  0  0

                        4  4  0  0  0  0  0  0

                           4  4  0  0  0  0  0

                              4  4  0  0  0  0

                                 4  4  0  0  0

                                    4  4  0  0

                                       4  4  0

                                          4  4

_________________________________________________

   0  0  4  8  8  8  8  8  8  8  8  8  8  8  4
∴ -4.4000000000 × 0.111111111111 = -0.48888888888840000000000000000000000000000000000000

OS

  • All OSs are affected

Additional context

None yet

Metadata

Metadata

Assignees

Labels

C-C++Code - Pull requests that update C++ code.T-BugType - Bug and unexpected behavior.T-ImprovementType - Improvements to components.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions