General
cancel
Showing results for
Did you mean:

SOLVED
Go to solution

## adding 2 large integer numbers on ia64 gives negative results

Hi All,

While adding two large integer numbers using expr command we discovered that the outcome becomes negative. (Small numbers are fine).

This happened on ALL our HP-UX ia64 servers.

Any idea?

4 REPLIES
Acclaimed Contributor
Solution

## Re: adding 2 large integer numbers on ia64 gives negative results

HI:

This is due to 32-bit arithmetic. Use 'bc' or 'adb' or 'awk' or 'perl' to perform your arithmetic. The 'ksh' shell at 11.23 will do 64-bit arithmetic too.

Y=2147483647
# X=\$(expr \$Y + 1);echo \$Xecho
-2147483648

# echo \$Y|awk '{printf "%10.0f\n",\$0+1}'
2147483648

Regards!

...JRF...
Honored Contributor

## Re: adding 2 large integer numbers on ia64 gives negative results

> This is due to 32-bit arithmetic. [...]

No, this is due to _signed_ arithmetic. The
number of bits merely determines what "large"
is.

When I was young, learning about computers
involved learning how computers count. (That
was back when computers were used mostly for
computation. It's been a while.) I gather
that this is less common now.
Esteemed Contributor

## Re: adding 2 large integer numbers on ia64 gives negative results

For big numbers use external commands like bc:

\$ echo \$((17179869184+17179869184))
0
\$ echo "17179869184+17179869184"|bc
34359738368

My 2 cents,
Armin