<?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: bc and rounding ... in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788455#M781576</link>
    <description>Hi Daniel:&lt;BR /&gt;&lt;BR /&gt;Perl's POSIX module (part of its standard distribution) offers the 'floor' and 'ceil' functions in addition ot 'int' for rounding.&lt;BR /&gt;&lt;BR /&gt;While the standard 'int' returns the integer part of a floating point number,  truncates the fractional part.  Thus, it rounds down for positive numbers and up for negative ones.  If you use the POSIX module you have 'floor' and 'ceil' available.  'floor' always rounds down regardless of the number's sign, while 'ceil' always rounds up, regardless of the sign.&lt;BR /&gt;&lt;BR /&gt;use POSIX qw(floor, ceil);&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
    <pubDate>Mon, 22 May 2006 13:09:26 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-05-22T13:09:26Z</dc:date>
    <item>
      <title>bc and rounding ...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788451#M781572</link>
      <description>Hi, folks.&lt;BR /&gt;&lt;BR /&gt;I'd like to generate some general discussion about mathematics in HP-UX from the shell, starting with:&lt;BR /&gt;&lt;BR /&gt;- How does one do rounding in "bc"?&lt;BR /&gt;- Does anyone know where I could find the "bc tutorial in Number Processing Users Guide" referenced in the bc man page?&lt;BR /&gt;- Is there a good beginners' reference for dc?&lt;BR /&gt;- Do either of the above calculate standard deviation, solving matrices, or other interesting math/statistics?  (Deliberately left wide open!)&lt;BR /&gt;&lt;BR /&gt;(I know the perl and mathomatic guys are going to have a field day with this, and the input is certainly welcome, though the question is focused on HP-UX default-OS utilities.)</description>
      <pubDate>Mon, 15 May 2006 14:44:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788451#M781572</guid>
      <dc:creator>A. Daniel King_1</dc:creator>
      <dc:date>2006-05-15T14:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: bc and rounding ...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788452#M781573</link>
      <description>Since bc performs real number math (fractions included), normal math steps are used for rounding. To round to 2 decimal positions, multiply the number by 100, add 0.5, convert the result to an integer and then divide by 100.&lt;BR /&gt; &lt;BR /&gt;Unfortunately, the bc man page is badly out of date as far as the manual "Number Processing Users Guide". The last time I saw that book was HP-UX 8.0, maybe 9.0, but apparently it went out of print before it could be converted to a PDF and sent to hppt://docs.hp.com&lt;BR /&gt; &lt;BR /&gt;It is even tricky to locate on the net...here are some references:&lt;BR /&gt; &lt;BR /&gt;&lt;A href="http://www.unixprogram.com/bc.pdf" target="_blank"&gt;http://www.unixprogram.com/bc.pdf&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.answers.com/topic/bc-programming-language" target="_blank"&gt;http://www.answers.com/topic/bc-programming-language&lt;/A&gt;&lt;BR /&gt; &lt;BR /&gt;There are some GNU bc manuals...much of it will apply, but as with most GNU tools, there are enhancements...&lt;BR /&gt; &lt;BR /&gt;&lt;A href="http://www.numbertheory.org/gnubc/gnubc.html" target="_blank"&gt;http://www.numbertheory.org/gnubc/gnubc.html&lt;/A&gt;&lt;BR /&gt; &lt;BR /&gt;and for dc&lt;BR /&gt; &lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Dc_(Unix)" target="_blank"&gt;http://en.wikipedia.org/wiki/Dc_(Unix)&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 May 2006 16:06:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788452#M781573</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2006-05-15T16:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: bc and rounding ...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788453#M781574</link>
      <description>Here's my function for rounding in bc:&lt;BR /&gt;&lt;BR /&gt;define r (a,s) {&lt;BR /&gt;  auto z,f,n  &lt;BR /&gt;&lt;BR /&gt;  n = 0;&lt;BR /&gt;  z=scale;&lt;BR /&gt;  scale=s+1;&lt;BR /&gt;  &lt;BR /&gt;  if (a &amp;lt; 0) { n = 1; a = -(a) }&lt;BR /&gt;  f=a + (5 / 10^(s + 1));&lt;BR /&gt;  scale=s;&lt;BR /&gt;  f=(f * (10^s)) / (10^s);&lt;BR /&gt;  if (n &amp;gt; 0) f = -(f);&lt;BR /&gt;  scale=z;&lt;BR /&gt;  return(f)&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;a=r(4.976,2)&lt;BR /&gt;a&lt;BR /&gt;4.98&lt;BR /&gt;&lt;BR /&gt;You send in the value and the number of desired decimal places. Note that the rounding assumes a radix of 10.&lt;BR /&gt;&lt;BR /&gt;While one could use bc to do more complex math, it's much like using a file to cut threads on a bolt. Yes it can be done but a die is a much better tool. Nowadays, Perl can be considered "Standard Equipment" on virtually any UNIX box and would be a far better choice for complex math. Bc and dc really only make sense with numbers with extremely high-precision and needed and even there Perl's Math::BigFloat and/or Math::BigInt modules make much more sense although that would require the installation of non-standard modules.</description>
      <pubDate>Mon, 15 May 2006 16:54:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788453#M781574</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-05-15T16:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: bc and rounding ...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788454#M781575</link>
      <description>From the bc.pdf link ...&lt;BR /&gt;&lt;BR /&gt;"BC is a language and a compiler for doing arbitrary precision arithmetic on the PDP-11&lt;BR /&gt;under the UNIXâ &amp;nbsp; time-sharing system."&lt;BR /&gt;&lt;BR /&gt;I'm loving it.  Handed down with the monolith from 2001 ...&lt;BR /&gt;&lt;BR /&gt;I was hoping there would be some built-in functions; I guess there are not so many as I had hoped.&lt;BR /&gt;&lt;BR /&gt;Anyone else?  No mathomatic folks?</description>
      <pubDate>Mon, 22 May 2006 12:37:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788454#M781575</guid>
      <dc:creator>A. Daniel King_1</dc:creator>
      <dc:date>2006-05-22T12:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: bc and rounding ...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788455#M781576</link>
      <description>Hi Daniel:&lt;BR /&gt;&lt;BR /&gt;Perl's POSIX module (part of its standard distribution) offers the 'floor' and 'ceil' functions in addition ot 'int' for rounding.&lt;BR /&gt;&lt;BR /&gt;While the standard 'int' returns the integer part of a floating point number,  truncates the fractional part.  Thus, it rounds down for positive numbers and up for negative ones.  If you use the POSIX module you have 'floor' and 'ceil' available.  'floor' always rounds down regardless of the number's sign, while 'ceil' always rounds up, regardless of the sign.&lt;BR /&gt;&lt;BR /&gt;use POSIX qw(floor, ceil);&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 22 May 2006 13:09:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/bc-and-rounding/m-p/3788455#M781576</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-05-22T13:09:26Z</dc:date>
    </item>
  </channel>
</rss>

