Operating System - HP-UX
1823376 Members
2428 Online
109654 Solutions
New Discussion юеВ

Is there integer limit in HP-UX ksh?

 
Louis Liu_1
New Member

Is there integer limit in HP-UX ksh?

I added 2 big integer numbers and got a negative number. for example:

$ (( i = 4190246798 + 4190246798 ))
$ echo $i
-209440996

Please ksh expert explain the reason.
BTW, I try the same example in Solaris, Solaris ksh can give correct result. Please try.
5 REPLIES 5
Ralph Grothe
Honored Contributor

Re: Is there integer limit in HP-UX ksh?

You should use bc for those bigint arithmetics.
I'm not sure if a typeset -i declaration can cope, but man ksh should tell.
Madness, thy name is system administration
john korterman
Honored Contributor

Re: Is there integer limit in HP-UX ksh?

Hi,

the posix shell only supports 32 bits integers, i.e. max 2147483648

Try Ralph's suggestion, e.g.:
# echo "4190246798 + 4190246798" | bc
8380493596

regards,
John K.
it would be nice if you always got a second chance
Peter Godron
Honored Contributor

Re: Is there integer limit in HP-UX ksh?

Louis,
looks like 2^31 is the limit.

A. Clay Stephenson
Acclaimed Contributor

Re: Is there integer limit in HP-UX ksh?

It's a 32-bit signed integer and thus the range is -(2^31) to +(2^31 - 1).
If it ain't broke, I can fix that.
Peter Godron
Honored Contributor

Re: Is there integer limit in HP-UX ksh?

Louis,
if you are happy with the solutions given, can you please reward good answers, see

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

and close the thread.