From: Benoit Lefebvre on
I am working on a script that will be used on IBM AIX and HP-UX
machines and I have encountered a little "weirdness" with the output
of the command /usr/bin/test on HP-UX

Here is the command run on IBM AIX:
[blefebvre(a)aix.server (/home/blefebvre)]: test "2614001721510" -gt
"261200170001" ; echo $?
0

Here is the same command run on HP-UX:
hpux.server:blefebvre:/home/blefebvre > test "2614001721510" -gt
"261200170001" ; echo $?
1

The number 2614001721510 is definitively greater than the number
261200170001.
Can it be an error in the /usr/bin/test binary on the HP-UX side ?

I have tried on HP-UX 11.11 and 11.23 I get the same output
AIX 5.3, 5.2 and 4.3 don't have the problem.
From: Ersek, Laszlo on
In article <4b7adec2-255e-455f-80c3-573c85fec428(a)s19g2000vbm.googlegroups.com>, Benoit Lefebvre <benoit.lefebvre(a)gmail.com> writes:
> I am working on a script that will be used on IBM AIX and HP-UX
> machines and I have encountered a little "weirdness" with the output
> of the command /usr/bin/test on HP-UX
>
> Here is the command run on IBM AIX:
> [blefebvre(a)aix.server (/home/blefebvre)]: test "2614001721510" -gt
> "261200170001" ; echo $?
> 0
>
> Here is the same command run on HP-UX:
> hpux.server:blefebvre:/home/blefebvre > test "2614001721510" -gt
> "261200170001" ; echo $?
> 1

The AIX test utility evaluates the -gt operator with 64 bit integers.
The HP-UX one likely first truncates the arguments to 32 bits signed,
then the resulting values are probably negative in two's complement
representation, and their relationship is the opposite of what was
meant.

decimal 2,614,001,721,510
binary 10,01100000,10011110,10100100,11100000,10100110
truncated to 32 bits: 10011110,10100100,11100000,10100110
(highest bit / sign bit set)
back to decimal: -1,633,361,754

decimal 261,200,170,001
binary 111100,11010000,10111110,01001100,00010001
truncated to 32 bits: 11010000,10111110,01001100,00010001
(highest bit / sign bit set)
back to decimal: -792,835,055

decimal > decimal
back to decimal < back to decimal

Use bc instead:

bc - arbitrary-precision arithmetic language

http://www.opengroup.org/onlinepubs/007908775/xcu/bc.html
http://www.opengroup.org/onlinepubs/007908775/xcu/test.html

Cheers,
lacos
From: Stephane CHAZELAS on
2010-01-19, 06:37(-08), Benoit Lefebvre:
> I am working on a script that will be used on IBM AIX and HP-UX
> machines and I have encountered a little "weirdness" with the output
> of the command /usr/bin/test on HP-UX
>
> Here is the command run on IBM AIX:
> [blefebvre(a)aix.server (/home/blefebvre)]: test "2614001721510" -gt
> "261200170001" ; echo $?
> 0
>
> Here is the same command run on HP-UX:
> hpux.server:blefebvre:/home/blefebvre > test "2614001721510" -gt
> "261200170001" ; echo $?
> 1

Are you sure you're not running the "test" command built in your
shell? What does "type test" tell you?

> The number 2614001721510 is definitively greater than the number
> 261200170001.

Except when you map it to a 32bit integer.

~$ echo $((2614001721510 & 0xffffffff))
2661605542
~$ echo $((261200170001 & 0xffffffff))
3502132241


> Can it be an error in the /usr/bin/test binary on the HP-UX side ?

It could be that "test" works with 32bit integers.

Try using "bc" or "dc" if you want to deal with any size of integers.

I think ksh93 uses floating points for arithmetics, so you may
have more luck with it, but then there are some limits as well:

~$ ksh -c 'test 10000000000000000 -lt 10000000000000001 || echo no'
no

--
St�phane
From: Eric Sosman on
On 1/19/2010 9:37 AM, Benoit Lefebvre wrote:
> I am working on a script that will be used on IBM AIX and HP-UX
> machines and I have encountered a little "weirdness" with the output
> of the command /usr/bin/test on HP-UX
>
> Here is the command run on IBM AIX:
> [blefebvre(a)aix.server (/home/blefebvre)]: test "2614001721510" -gt
> "261200170001" ; echo $?
> 0
>
> Here is the same command run on HP-UX:
> hpux.server:blefebvre:/home/blefebvre> test "2614001721510" -gt
> "261200170001" ; echo $?
> 1
>
> The number 2614001721510 is definitively greater than the number
> 261200170001.

... and both are definitively greater than 2^31. If
you chop them to 32 bits (two's complement), the two numbers
become -2661605542 and -792835055, respectively, and the first
is less than (more negative than) the second.

> Can it be an error in the /usr/bin/test binary on the HP-UX side ?

I don't know whether there's a formal spec covering what
/usr/bin/test does with large-magnitude integers.

> I have tried on HP-UX 11.11 and 11.23 I get the same output
> AIX 5.3, 5.2 and 4.3 don't have the problem.

A guess: HP-UX' version is built as a 32-bit program, while
AIX' is 64-bit. (I repeat: This is a guess.)

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Rainer Weikusat on
Benoit Lefebvre <benoit.lefebvre(a)gmail.com> writes:
> I am working on a script that will be used on IBM AIX and HP-UX
> machines and I have encountered a little "weirdness" with the output
> of the command /usr/bin/test on HP-UX
>
> Here is the command run on IBM AIX:
> [blefebvre(a)aix.server (/home/blefebvre)]: test "2614001721510" -gt
> "261200170001" ; echo $?
> 0
>
> Here is the same command run on HP-UX:
> hpux.server:blefebvre:/home/blefebvre > test "2614001721510" -gt
> "261200170001" ; echo $?
> 1
>
> The number 2614001721510 is definitively greater than the number
> 261200170001.
> Can it be an error in the /usr/bin/test binary on the HP-UX side ?

My guess would be that the HP-UX test uses a 32-bit integer type which
cannot represent either value.