in reply to Re: Compare two signed integers without using comparision operator in perl
in thread Compare two signed integers without using comparision operator in perl

You can use string comparison on positive, unsigned integers, or even unsigned floating point numbers, if you make sure the number of digits left of the decimal point (if any) are the same for all numbers. Thus, after using sprintf with a proper template.

This doesn't work if at least one of the numbers is negative.

I don't think it matters for this particular case, as string comparison is comparison nevertheless, but still... It's the only reason I can think of why the sign would matter.

p.s. It's even an excellent way to compare groups of strings/numbers in one comparison, for example, for sort.

  • Comment on Re: Re: Compare two signed integers without using comparision operator in perl