<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UNIX arithmetic in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614363#M104476</link>
    <description>Pardon the flaw in the exaples.  I have used this a number of times for the same issue.  Let me find a good example.  Will get back to you.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hold on.</description>
    <pubDate>Mon, 29 Aug 2005 17:06:50 GMT</pubDate>
    <dc:creator>Tim Nelson</dc:creator>
    <dc:date>2005-08-29T17:06:50Z</dc:date>
    <item>
      <title>UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614361#M104474</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a bsic quetion on Unix aritmetic. &lt;BR /&gt;&lt;BR /&gt;Below is the sample script&lt;BR /&gt;&lt;BR /&gt;val1=16019&lt;BR /&gt;val2=2&lt;BR /&gt;val3=`expr $val1 / $val2`&lt;BR /&gt;&lt;BR /&gt;the result should actually be "8009.5" but I am getting "8009".&lt;BR /&gt;&lt;BR /&gt;Can anyone please tell me what I need to do to get the value "8009.5" as the result.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Rahul&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2005 16:55:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614361#M104474</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2005-08-29T16:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614362#M104475</link>
      <description>all shells are integer math.  Cannot do FP.&lt;BR /&gt;&lt;BR /&gt;use "bc" for math.&lt;BR /&gt;&lt;BR /&gt;echo 3.5+2|bc&lt;BR /&gt;5.5&lt;BR /&gt;&lt;BR /&gt;or echo $val1/$val2|bc&lt;BR /&gt;&lt;BR /&gt;you get the idea.&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2005 17:03:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614362#M104475</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2005-08-29T17:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614363#M104476</link>
      <description>Pardon the flaw in the exaples.  I have used this a number of times for the same issue.  Let me find a good example.  Will get back to you.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hold on.</description>
      <pubDate>Mon, 29 Aug 2005 17:06:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614363#M104476</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2005-08-29T17:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614364#M104477</link>
      <description>As far as I know, only arithmetic in ksh or any standart shell for that matter, is integer arithmetic. You need to devise your floating point arithmetics yourself. One time I have bookmarked this link for the purpose but never tried it. Take a peek at the script found at the following url and see if it helps you.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.shelldorado.com/scripts/cmds/calc" target="_blank"&gt;http://www.shelldorado.com/scripts/cmds/calc&lt;/A&gt;</description>
      <pubDate>Mon, 29 Aug 2005 17:09:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614364#M104477</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-08-29T17:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614365#M104478</link>
      <description>Try this&lt;BR /&gt;&lt;BR /&gt;val3=`echo "$val1/$val2"|bs`&lt;BR /&gt;&lt;BR /&gt;echo $val3&lt;BR /&gt;&lt;BR /&gt;Don't ask about the bs, it just works :)&lt;BR /&gt;&lt;BR /&gt;read the man page on bs and you will understand.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2005 17:10:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614365#M104478</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2005-08-29T17:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614366#M104479</link>
      <description>Rahul,&lt;BR /&gt;&lt;BR /&gt;Use the command line example suggested by Tim. You'll have to do the same operation in case of further manipulation of the string stored inside of val3 ex. if you need to multiply val3 by 3 to obtain 24028.5 then...&lt;BR /&gt;&lt;BR /&gt;# val4=`echo "$val3*3"|bs`&lt;BR /&gt;&lt;BR /&gt;hope it helps!!!</description>
      <pubDate>Mon, 29 Aug 2005 17:22:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614366#M104479</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-29T17:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614367#M104480</link>
      <description>Make sure that you're not typesetting the variables within your script to integer otherwise integer truncation would chop off the decimal part i.e. remove any line(s) like "typeset -i val1 val2 val3"&lt;BR /&gt;&lt;BR /&gt;regards!</description>
      <pubDate>Mon, 29 Aug 2005 18:27:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614367#M104480</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-29T18:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614368#M104481</link>
      <description>Just to clarify, Unix isn't doing the arithmetic, it is your shell. All popular Unix shells are limited to integer arithmetic. AS mentioned, you can use bc to perform your floating point calculations but remember that the shell built-in commands such as eval and let will truncate variables to integers.&lt;BR /&gt; &lt;BR /&gt;Now shell variables can be assigned values such as val9=123.9567 and it will look correct. That is because the shell defaults all variables to strings, not numbers. And when a variable is used in shell arithmetic, the value is reduced to an integer by truncation (not rounding). So the examp,e val9=123.9567 will be used as 123 and not rounded to 124. If you need to make calculations that may result in a fractional part, use the shell variables as string holders and do all the calculations in bc.</description>
      <pubDate>Tue, 30 Aug 2005 11:24:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614368#M104481</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-08-30T11:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614369#M104482</link>
      <description>ksh is completely incapable of doing floating point arithmetic.&lt;BR /&gt;&lt;BR /&gt; You have to do it with "awk".&lt;BR /&gt;&lt;BR /&gt; Say you want to divide 5.12 by 21.56:&lt;BR /&gt;&lt;BR /&gt;  TIME=21.56&lt;BR /&gt;  echo 5.12 $TIME | awk '{printf "%.2f\n", $1 / $2 }'&lt;BR /&gt;&lt;BR /&gt; yields:&lt;BR /&gt;&lt;BR /&gt;  0.24&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2005 11:38:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614369#M104482</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-08-30T11:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX arithmetic</title>
      <link>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614370#M104483</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Some modern shells, notably Korn93 and decendents, DO HAVE the ability to perform real arithmetic.  You use the '-F' or -'E' typeset options.&lt;BR /&gt;&lt;BR /&gt;The '-E' option specifies scientific notation.  An option count (n) signifies the number of significant places.  Similarly, '-F' asks for floating point notation with an option n-count signaling the number of decimal places.&lt;BR /&gt;&lt;BR /&gt;On HP-UX, you can find a version as:&lt;BR /&gt;&lt;BR /&gt;/usr/dt/bin/dtksh&lt;BR /&gt;&lt;BR /&gt;By example:&lt;BR /&gt;&lt;BR /&gt;#!/usr/dt/bin/dtksh&lt;BR /&gt;typeset -F  R1&lt;BR /&gt;typeset -F3 R2&lt;BR /&gt;typeset -E  R3&lt;BR /&gt;let R1=1/8&lt;BR /&gt;echo $R1&lt;BR /&gt;let R2=1/8&lt;BR /&gt;echo $R2&lt;BR /&gt;let R3=1/8&lt;BR /&gt;echo $R3&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...produces as output:&lt;BR /&gt;&lt;BR /&gt;.1250000000&lt;BR /&gt;.125&lt;BR /&gt;0.125&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 30 Aug 2005 11:45:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/unix-arithmetic/m-p/3614370#M104483</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-08-30T11:45:34Z</dc:date>
    </item>
  </channel>
</rss>

