- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: arithmetic operations problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 09:41 PM
тАО05-31-2005 09:41 PM
This is using POSIX shell.
I.
#((x=1000000000+1));echo $x
1000000001
II.
#((x=10000000000+1));echo $x
1410065409
I notice that POSIX is not capable of computing more that 10 digit. Is there a way around this? Any other alternative?
Regards,
Paul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 09:58 PM
тАО05-31-2005 09:58 PM
Re: arithmetic operations problem
Try this:
((x=500000000+1));((y=500000000));echo $x;echo $y;((z=$y+$x));echo $z
Best Regards,
Eric Antunes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 10:26 PM
тАО05-31-2005 10:26 PM
Re: arithmetic operations problem
((x=500000000+1));((y=500000000));echo $x;echo $y;((z=$y+$x));echo $z
From you example the value of x is still less than 10.
What I need is for a way to compute 11 digit integer.
Regards,
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 10:34 PM
тАО05-31-2005 10:34 PM
Solutionintegers range are: from -2^31 (-2147483648) to +2^31-1 (+2147483647)
Following commands show only low 32-bit are used:
(( x=2147483647)); (( x=x+1 )); echo $x
-2147483648
I should use "bc" command (or "dc" utility) instead.
- Tags:
- bc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 10:39 PM
тАО05-31-2005 10:39 PM
Re: arithmetic operations problem
Take a look at Knowledge Base Doc. ID 4000099480 . This explains workarounds to 32 bit integer limitations.
Regards,
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 10:44 PM
тАО05-31-2005 10:44 PM
Re: arithmetic operations problem
echo 10000000000+1 | bc | read x
echo $x
Note that the 32-bit arithmetic is also applicable to INTEGER shell variables defined by means of 'typeset -i' (or 'integer' alias). Therefore, the shell variables used to handle this big values HAVE TO BE NON-INTEGER.
The following examples:
typeset -i x
echo 10000000000+1 | bc | read x
echo $x
typeset +i x
echo 10000000000+1 | bc | read x
echo $x
wil print:
1410065409
10000000001
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 11:00 PM
тАО05-31-2005 11:00 PM
Re: arithmetic operations problem
I also have this 32 bits maximum:
2^0+2^1+...+2^31=2^32-2^0=4294967296-1=4294967295 but since we also need to use negative numbers, our limit is as CAS said...
Best Regards,
Eric Antunes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2005 07:35 PM
тАО06-02-2005 07:35 PM
Re: arithmetic operations problem
I have problem storing the output of bc into variable. I need to get to correct results and process it further.
cscpcc@idmp005 [/home/cscpcc]
#print "2124582832+256000000"|bc
2380582832
cscpcc@idmp005 [/home/cscpcc]
#print "2124582832+256000000"|bc|read x|echo $x
-1914384464
Regards,
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2005 07:47 PM
тАО06-02-2005 07:47 PM
Re: arithmetic operations problem
# print "2124582832+256000000"|bc|read x;echo $x
(i.e. lose the last pipe)
Works for me!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2005 07:48 PM
тАО06-02-2005 07:48 PM