Number comparison in ksh on mac with -lt is giving wrong answer

I am trying to run following script in ksh on darwin 11.4.2:

freeSpace=2469606195
spaceNeeded=200
[[ $freeSpace -lt $spaceNeeded ]] && echo "no space" || echo "space available"
[[ $freeSpace < $spaceNeeded ]] && echo "no space" || echo "space available"

"-lt" is giving wrong answer as "no space" Whereas '<' works fine. When I change the freespace value to 5469606195, '-lt' works again. So, its not really limit on variable size or something. Behavior is very weird. Any idea, whats going wrong here?.

< > are redirection in shell, not greater-than less-than.

Testing in bash, -lt works fine, so I believe you are just hitting the limits on integer size in your shell.

Thanks corona. Yes I too saw that it works in bash. I am hitting issue only in ksh and that too only on Mac.

-lt does a numerical comparison, while < does a string comparison. 200 is less than 2469606195 for both comparisons. Try the operators using either A and B, or 2469606195 and 20000000000, and you will see the difference.

It'd be ugly, but one way to do it on shells with 32-bit integers may be zero-padding your numbers to a fixed number of digits, then using string comparison. String comparison should be reliable on digit strings of identical length.