Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

expr command: number limitation... how high can it goes???

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
how high a number goes for an expr command?

in a shell script, I have:

total_max_bytes=`expr $total_max_bytes + $max_bytes`

Suprising, it goes down to negative. the script failed to capture the number:

I ran this manually from the command line:
expr 427819080 + 2139095040

result returns: -1728053176 (????) instead of 6417285120

how do I handle large number in a regular addition?

Thanks,
 
pho01,

bc should work fine. The correct answer is 2566914120.

echo "427819080 + 2139095040"| bc
2566914120

John
 
pho01,

From man expr...
Internally, integers are treated as 32-bit, 2's complement numbers.

So you can add up to two 9-digit numbers together.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top