Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inequality tests of longs do not work for negative numbers. #268

Closed
@warownia1

Description

@warownia1

The inequality test methods $le, $lt, $ge, $gt for Long type return incorrect answers for negative longs using array notation.

Example 1 - comparing two "large" longs:

long a = -30000000000000000L;
long b = -70000000000000000L;

assert a > b; 
assert a >= b;
assert b < a;
assert b <= a;

Example 2 - comparing "large" long with "small" long:

long a = -1;
long b = -(1L << 54);

assert a > b; 
assert a >= b;
assert b < a;
assert b <= a;

Example 3 - comparing two "small" longs:

long a = Long.parseLong("-1");
long b = Long.parseLong("-2");

assert a > b;
assert a >= b;
assert b < a;
assert b <= a;

All assertions in the examples above fail.

I think the problem is the implementation of the inequality comparisons which compare a[1] to b[1] and then a[0] to b[0] with no regard to signs of the numbers a[2], b[2].
I suggest fixing the $cmp method and then making all other comparisons rely on this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions