<?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: Floting point operation in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273640#M656546</link>
    <description>HI (again) Den:&lt;BR /&gt;&lt;BR /&gt;One example, using your data:&lt;BR /&gt;&lt;BR /&gt;# cat ./info&lt;BR /&gt;opclmqa1 15.0&lt;BR /&gt;opclmqa1 0.1&lt;BR /&gt;opclmqa1 0.2&lt;BR /&gt;opclmqa1 0.0&lt;BR /&gt;&lt;BR /&gt;# awk '{SUM+=$2};END{printf "%6.1f\n",SUM}' ./info&lt;BR /&gt;  15.3&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
    <pubDate>Thu, 10 Feb 2011 22:21:11 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2011-02-10T22:21:11Z</dc:date>
    <item>
      <title>Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273637#M656543</link>
      <description>Hi Guys&lt;BR /&gt;&lt;BR /&gt;Here my script&lt;BR /&gt;&lt;BR /&gt;for instance in $(.........)&lt;BR /&gt;do &lt;BR /&gt;&lt;BR /&gt;  (( mySum= 0.0000 )) &lt;BR /&gt;  # &lt;BR /&gt;  for PID in $(.....)&lt;BR /&gt;  do   &lt;BR /&gt;     lecture=$( here a call to a function returning float value )&lt;BR /&gt;     echo $instance $lecture &lt;BR /&gt;     (( mySum =  $mySum + $lecture ))         &lt;BR /&gt;  done &lt;BR /&gt;   print "mySum=" $mySum&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and the result:&lt;BR /&gt;&lt;BR /&gt;(Example)&lt;BR /&gt;&lt;BR /&gt;opclmqa1 15.0&lt;BR /&gt;opclmqa1 0.1&lt;BR /&gt;opclmqa1 0.2&lt;BR /&gt;opclmqa1 0.0&lt;BR /&gt;&lt;BR /&gt;mySum= 15&lt;BR /&gt;&lt;BR /&gt;I should have 15.3 &lt;BR /&gt;&lt;BR /&gt;why ? and how to fix ?&lt;BR /&gt;&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den</description>
      <pubDate>Thu, 10 Feb 2011 21:44:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273637#M656543</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2011-02-10T21:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273638#M656544</link>
      <description>Hi Den:&lt;BR /&gt;&lt;BR /&gt;Most shells only support integer arithmetic.&lt;BR /&gt;&lt;BR /&gt;# X=100;Y=25;((Z=X/Y));echo $Z&lt;BR /&gt;&lt;BR /&gt;If you want to incorporate real numbers, 'bc' provides a convenient vehicle. Choose the 'scale' to set the precision you want:&lt;BR /&gt;&lt;BR /&gt;# X=1;Y=8;echo "scale=3\n $X/$Y"|bc&lt;BR /&gt;&lt;BR /&gt;You can also leverage 'awk' and couple it with 'printf' to format output, including moving to a different number base:&lt;BR /&gt;&lt;BR /&gt;# X=1;Y=8;echo "$X $Y"|awk '{printf "%.4f\n",$1/$2}'&lt;BR /&gt;&lt;BR /&gt;# X=7;Y=8;echo "$X $Y"|awk '{printf "%4x\n",$1+$2}'&lt;BR /&gt;&lt;BR /&gt;The standard Korn shell in HP-UX is Korn88 and does integer arithmetic.  However, if you use the Korn93 (found in HP-UX as '/usr/dt/bin/dtksh') shell, its 'typeset' allows a more direct approach to real numbers:&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;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 10 Feb 2011 21:53:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273638#M656544</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-02-10T21:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273639#M656545</link>
      <description>Hi James&lt;BR /&gt;&lt;BR /&gt;HUmm, but how to do a sum in this case ? it seems difficult like this. &lt;BR /&gt;&lt;BR /&gt;Have a nice end day&lt;BR /&gt;Thanks James.</description>
      <pubDate>Thu, 10 Feb 2011 22:03:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273639#M656545</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2011-02-10T22:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273640#M656546</link>
      <description>HI (again) Den:&lt;BR /&gt;&lt;BR /&gt;One example, using your data:&lt;BR /&gt;&lt;BR /&gt;# cat ./info&lt;BR /&gt;opclmqa1 15.0&lt;BR /&gt;opclmqa1 0.1&lt;BR /&gt;opclmqa1 0.2&lt;BR /&gt;opclmqa1 0.0&lt;BR /&gt;&lt;BR /&gt;# awk '{SUM+=$2};END{printf "%6.1f\n",SUM}' ./info&lt;BR /&gt;  15.3&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Feb 2011 22:21:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273640#M656546</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-02-10T22:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273641#M656547</link>
      <description>Arrr. Sorry I have reopen it. &lt;BR /&gt;&lt;BR /&gt;Finally I prefer to build my list&lt;BR /&gt;and then I'm able to have this ...&lt;BR /&gt;&lt;BR /&gt;echo $a&lt;BR /&gt;1.1 1.0 23.10 1.4 0.8 0.0 0.0&lt;BR /&gt;&lt;BR /&gt;How to have the sum of all float number in my variable ?&lt;BR /&gt;&lt;BR /&gt;Bests regards&lt;BR /&gt;Denis A. Jeanneret</description>
      <pubDate>Fri, 11 Feb 2011 13:56:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273641#M656547</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2011-02-11T13:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273642#M656548</link>
      <description>It's ok&lt;BR /&gt;&lt;BR /&gt;With a pipe against awk '{s=0; for (i=1; i&amp;lt;=NF; i++) s=s+$i; print s}'&lt;BR /&gt;&lt;BR /&gt;Thanks James, have a nice week end&lt;BR /&gt;Bests regards&lt;BR /&gt;Den&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Feb 2011 14:13:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273642#M656548</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2011-02-11T14:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273643#M656549</link>
      <description>James Solution is efficient with my small addons.</description>
      <pubDate>Fri, 11 Feb 2011 14:13:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273643#M656549</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2011-02-11T14:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Floting point operation</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273644#M656550</link>
      <description>&amp;gt;How to have the sum of all float number in my variable?&lt;BR /&gt;&lt;BR /&gt;Instead of looping in awk, you can loop in the shell:&lt;BR /&gt;for i in $a; do echo $i; done |&lt;BR /&gt;awk '{SUM+=$1};END{printf "%6.1f\n",SUM}'</description>
      <pubDate>Sat, 12 Feb 2011 10:34:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/floting-point-operation/m-p/5273644#M656550</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-02-12T10:34:54Z</dc:date>
    </item>
  </channel>
</rss>

