natorder icon indicating copy to clipboard operation
natorder copied to clipboard

Char and int comparison

Open 616slayer616 opened this issue 4 years ago • 5 comments

Line 51 is never true for all the examples I put into it.

https://github.com/paour/natorder/blob/ab9e2dfd165736a90f3d8784e76c906e6603db52/NaturalOrderComparator.java#L51

Is it supposed to compare with 0 (space) or with 48 (0)?

if (ca == '0' && cb == '0') {

616slayer616 avatar Jul 18 '19 08:07 616slayer616

The condition cannot evaluate to true because of

https://github.com/paour/natorder/blob/ab9e2dfd165736a90f3d8784e76c906e6603db52/NaturalOrderComparator.java#L42

If both ca and cb are 0 (space, non-digit) bias will be returned.

So L51 is either redundant or should be changed to check for 48 or '0' respectively

616slayer616 avatar Jul 18 '19 10:07 616slayer616

The line is indeed redundant: if both ca and cb are 0, then neither is a digit.

paour avatar Jul 18 '19 13:07 paour

Thank you for the clarification

616slayer616 avatar Jul 18 '19 13:07 616slayer616

Fixed by #9

paour avatar Jul 18 '19 13:07 paour

This is the wrong issue for PR #9

I have no PR for the redundancy issue because I was unsure.

PR #9 is for Issue #1

616slayer616 avatar Jul 18 '19 13:07 616slayer616