- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using division operator produces negative values
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
Forums
Discussions
Discussions
Discussions
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
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
06-23-2004 10:22 AM
06-23-2004 10:22 AM
let bytes_K=$bytes/1024
for example,
bytes_K = 4194304000
and output of code snippet is:
-98304
???
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:25 AM
06-23-2004 10:25 AM
Solutionsee what you get for numbers less then 2G and then for numbers over 2G
you'll probably have to use something like bc or perl to handle such large numbers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:36 AM
06-23-2004 10:36 AM
Re: Using division operator produces negative values
Maybe it did?
:-)
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:42 AM
06-23-2004 10:42 AM
Re: Using division operator produces negative values
echo "$bytes/1024" | bc -l
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:43 AM
06-23-2004 10:43 AM
Re: Using division operator produces negative values
Got around it by doing my units conversion to Kbytes while within the Oracle engine, but glad to know there was a valid issue there. I'll have to find a solid piece of code one of these days soon for handling division of large integers!
Gil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:45 AM
06-23-2004 10:45 AM
Re: Using division operator produces negative values
getconf LONG_MIN
getconf LONG_MAX
If your vales are outside this range then you need a plan B.
One simple solution is "bc".
Here is an an example:
#!/usr/bin/sh
kbytes()
{
typeset -i10 STAT=0
typeset N=${1}
shift
echo "scale=0; ${N} / 1024" | bc
STAT=${?}
return ${STAT}
} # kbytes
BYTES=4194304000
KBYTES=$(kbytes ${BYTES})
echo "Result = ${KBYTES} KB"
The "scale=0" set 0 decimal places in the result; "scale=2" would set 2 decimal places"
Man bc for more details. Bc can also be used for floating point calculations -- something that the shell will not do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 10:58 AM
06-23-2004 10:58 AM
Re: Using division operator produces negative values
422 let x=5
423 echo $x
5
424 let x=2000
425 echo $x
2000
426 let x=4194304000
427 echo $x
-100663296
now if I do
429 getconf LONG_MIN
-2147483648
430 getconf LONG_MAX
2147483647
Now if I do:
432 echo "$x/1024" | bc -l
-98304.00000000000000000000
I'll try out your expanded solution and see if it works for me...it's appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 11:06 AM
06-23-2004 11:06 AM