Operating System - Linux
1827809 Members
1997 Online
109969 Solutions
New Discussion

Any one can explain this?

 
SOLVED
Go to solution
okyour
Occasional Advisor

Any one can explain this?

thanks

bcdb-p03:/script_file/OS#de_percent=$(( 47816844 * 10 ))
bcdb-p03:/script_file/OS#echo $de_percent
478168440
bcdb-p03:/script_file/OS#de_percent=$(( 47816844 * 100 ))
bcdb-p03:/script_file/OS#echo $de_percent
486717104
5 REPLIES 5
Ralph Grothe
Honored Contributor

Re: Any one can explain this?

Probably owe to overrun.
I think the shell arithmetics only can handle 2^31 as maximum integer value (I think one bit is required for the sign)
The man page should mention the limitations.
You could resort to bc or perl, python for big ints.
Madness, thy name is system administration
Peter Nikitka
Honored Contributor

Re: Any one can explain this?

Hi,

A slight overrun will lead to negative numbers.
Now remember, that a '-' may be interpreted by the 'echo' or 'print' as an option.

My Sun ksh (64Bit) tells:

print $((47816844 * 100000000000))
4781684400000000000
print $((47816844 * 1000000000000))

print -- "$((47816844 * 1000000000000))"
-7523388221128654848

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
okyour
Occasional Advisor

Re: Any one can explain this?

Hi

Thanks for the reply. but how can I resolve this question,I need to write a script like this to check the memory treadhold,but if the memory is large,the script will get wrong result.plz give me further help

########### check memory added 09/04/2007

thresholdmem=10
de_phy=`more /var/adm/syslog/syslog.log|grep -i phy|grep available|awk '{print $7}'`
de_free=`more $State_File |grep Memory:|awk '{print $8}'|sed 's/K//p'`
de_percent=$(( $de_free * 100 / $de_phy ))

if [ $thresholdmem -gt $de_percent ]

then
echo "Current free Memory is : $de_percent %" >> $output_file
echo "Critical: Found that there is Memory issue! plz check it ASAP!!\n" >> $output_file
grep -i USERNAME $State_File >> $output_file

typeset i=1
while read -r yy
do
if [ $i -gt 15 ]
then
printf "%s \n" "$yy" >> $State_File2
fi

if [ $i -gt 1115 ]
then
break
fi
let i=i+1
done < $State_File

sort -r -k 8,8 $State_File2 >> $new_file2

typeset a=1
while read -r xx
do
if [ $a -gt 0 ]
then
printf "%s \n" "$xx" >> $output_file
fi

if [ $a -gt 20 ]
then
break
fi
let a=a+1
done < $new_file2
Peter Nikitka
Honored Contributor
Solution

Re: Any one can explain this?

Hi,

first choice:
come to lower numbers, in computing the values you use not in KB but MB - so you have a factor of 1/1024.

Another alternative would be the use of dc/awk/perl to get 64Bit integer arithmetik or floating point calculation.
E.G.
print "47816844 100*p" | dc

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
okyour
Occasional Advisor

Re: Any one can explain this?

Problem solved