<?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: Very large numbers in a script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057128#M719174</link>
    <description>perl&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
    <pubDate>Tue, 26 Aug 2003 19:19:01 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2003-08-26T19:19:01Z</dc:date>
    <item>
      <title>Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057127#M719173</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a script that needs to process a list of very large numbers with at least 8 places to the right of the decimal. The numbers are so large that the only tool that I have found that will add or subtract them is bc. I read each line from a file and then call bc to get the result. My problem is that bc is very slow and I need to calculate at least hundreds of these for on-line reports. It takes maybe 2 minutes to get the results. I tried awk but it doesn't work on these large numbers. Does anyone know of a fater tool?&lt;BR /&gt;&lt;BR /&gt;TIA,&lt;BR /&gt;Steve&lt;BR /&gt;</description>
      <pubDate>Tue, 26 Aug 2003 19:18:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057127#M719173</guid>
      <dc:creator>Stephen Taylor_1</dc:creator>
      <dc:date>2003-08-26T19:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057128#M719174</link>
      <description>perl&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Tue, 26 Aug 2003 19:19:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057128#M719174</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-08-26T19:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057129#M719175</link>
      <description>Harry! Please be a *little* bit more specific :)&lt;BR /&gt;&lt;BR /&gt;a5:/u/usr/merijn 109 &amp;gt; perl -Mbignum=a,50 -le 'print sqrt(20)'&lt;BR /&gt;4.4721359549995793928183473374625524708812367192231&lt;BR /&gt;a5:/u/usr/merijn 110 &amp;gt; perl -Mbigint -le'$x = 24354**24; print $x-&amp;gt;as_hex'&lt;BR /&gt;0x34e3b074445143af79a6d97d93787b0297b5697e1950d0b73e710c91a0f81c0eeb047b64edfcb5c981000000&lt;BR /&gt;a5:/u/usr/merijn 111 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
      <pubDate>Tue, 26 Aug 2003 19:36:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057129#M719175</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-08-26T19:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057130#M719176</link>
      <description>have you tried the dtksh shell&lt;BR /&gt;/usr/dt/bin/dtksh&lt;BR /&gt;&lt;BR /&gt;use typeset -F  fixed precision&lt;BR /&gt;or typeset -E   scientific&lt;BR /&gt;&lt;BR /&gt;for floating point numbers</description>
      <pubDate>Tue, 26 Aug 2003 19:40:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057130#M719176</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-08-26T19:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057131#M719177</link>
      <description>Ahh Merijn - Now you're just showing off  AND  having fun, I suspect.  ;~))&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Jeff</description>
      <pubDate>Tue, 26 Aug 2003 19:43:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057131#M719177</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2003-08-26T19:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057132#M719178</link>
      <description>I'm assuming that the number are very large and you want perfect precision -- thus floating-point is out. You could use Perl's BigInt module but I'm going to suggest a surprising tool -- the one you are using now, bc. You just need to be a bit smarter in how you invoke it.&lt;BR /&gt;&lt;BR /&gt;I'll guess that you are doing something like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;INFILE=myfile&lt;BR /&gt;TOT=0&lt;BR /&gt;cat ${INFILE} | while read X&lt;BR /&gt;  do&lt;BR /&gt;    TOT=$(echo scale=8; ${TOT} + ${X} | bc)&lt;BR /&gt;  done&lt;BR /&gt;echo "Total = ${TOT}"&lt;BR /&gt;&lt;BR /&gt;The problem is that each invocation of bc costs you a fork and an exec BUT if we could do this as a co-process then that overhead is gone and I will predict at least a 10X (and probably much greater) improvement.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;INFILE=myfile&lt;BR /&gt;TOT=0&lt;BR /&gt;&lt;BR /&gt;bc |&amp;amp;&lt;BR /&gt;print -p "scale=8"&lt;BR /&gt;cat ${INFILE} | while read X&lt;BR /&gt;  do&lt;BR /&gt;    print -p "${TOT} + ${X}"&lt;BR /&gt;    read -p TOT&lt;BR /&gt;  done&lt;BR /&gt;print -p "quit"&lt;BR /&gt;echo "Total = ${TOT}"&lt;BR /&gt;&lt;BR /&gt;You could improve this still further by using a register and simply adding to it:&lt;BR /&gt;e.g. print -p "a+=${X}"&lt;BR /&gt;&lt;BR /&gt;I think you will be amazed at how well this will work.&lt;BR /&gt;     &lt;BR /&gt;     &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 26 Aug 2003 19:49:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057132#M719178</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-08-26T19:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057133#M719179</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;Here's my still better version taking advantage of a bc register; in this case 'a'.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;INFILE=myfile&lt;BR /&gt;&lt;BR /&gt;bc |&amp;amp;&lt;BR /&gt;print -p "scale=8;a=0"&lt;BR /&gt;cat ${INFILE} | while read X&lt;BR /&gt;do&lt;BR /&gt;print -p "a+= ${X}"&lt;BR /&gt;done&lt;BR /&gt;print -p "a"&lt;BR /&gt;read -p TOT&lt;BR /&gt;print -p "quit"&lt;BR /&gt;echo "Total = ${TOT}"&lt;BR /&gt;&lt;BR /&gt;That should be about as fast as it will get \; ig you are do multi-columned calculations then you would need a register for each column but that exercise is left for the student.&lt;BR /&gt;&lt;BR /&gt;Regards (and it ain't always Perl), Clay&lt;BR /&gt;</description>
      <pubDate>Tue, 26 Aug 2003 20:13:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057133#M719179</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-08-26T20:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Very large numbers in a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057134#M719180</link>
      <description>Thanks everyone. I know I need to learn perl but Clay's solution was amazingly fast!!! It went from about 2 minutes to about 1 second!  I didn't know that the shell could read from and print to another process like that. That was a neat trick!&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Steve&lt;BR /&gt;</description>
      <pubDate>Tue, 26 Aug 2003 20:31:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/very-large-numbers-in-a-script/m-p/3057134#M719180</guid>
      <dc:creator>Stephen Taylor_1</dc:creator>
      <dc:date>2003-08-26T20:31:51Z</dc:date>
    </item>
  </channel>
</rss>

