Skip to content

Issues with double comparisons #135

@KabooHahahein

Description

@KabooHahahein
  1. Comparisons of negative values to 0.0 will always succeed
    Eg. assert_that_double(-500, is_equal_to_double(0));
    Occurs because the largest absolute value is computed from the absolute of the max of the values. It should be the max of the absolute values.

  2. Relative epsilon calculations with 0 and a very small number will fail
    Eg. assert_that_double(0.000000000000001, is_equal_to_double(0));
    Occurs because the implementation uses relative epsilons. The valid range for the above example is computed as [0.000000000000001001, 0.000000000000000999] if there are 4 significant figures. Thus, 0 should fail, but it is unintuitive.

  3. Comparisons of 0 with 0 rely on a integer overflow
    First of all, we should not be passing an invalid domain (0) to log10()
    Second of all, we should not be casting –Inf to integer then do a subtraction on it. This will cause an overflow.

  4. Comparisons with extremely small numbers will always return a failure
    Eg. assert_that_double(4.9406564584124654E-324, is_equal_to_double(4.9406564584124654E-324));
    Occurs because the calculated relative epsilon is smaller than the smallest real double value (represented by bits). This can be fixed by assigning the smallest real double as the relative epsilon, instead of letting the math go to 0

Note that issue 1 is a critical bug and should be fixed first (ASAP).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions