- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Very large numbers in a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 12:18 PM
08-26-2003 12:18 PM
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?
TIA,
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 12:19 PM
08-26-2003 12:19 PM
Re: Very large numbers in a script
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 12:36 PM
08-26-2003 12:36 PM
Re: Very large numbers in a script
a5:/u/usr/merijn 109 > perl -Mbignum=a,50 -le 'print sqrt(20)'
4.4721359549995793928183473374625524708812367192231
a5:/u/usr/merijn 110 > perl -Mbigint -le'$x = 24354**24; print $x->as_hex'
0x34e3b074445143af79a6d97d93787b0297b5697e1950d0b73e710c91a0f81c0eeb047b64edfcb5c981000000
a5:/u/usr/merijn 111 >
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 12:40 PM
08-26-2003 12:40 PM
Re: Very large numbers in a script
/usr/dt/bin/dtksh
use typeset -F fixed precision
or typeset -E scientific
for floating point numbers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 12:43 PM
08-26-2003 12:43 PM
Re: Very large numbers in a script
Cheers,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 12:49 PM
08-26-2003 12:49 PM
SolutionI'll guess that you are doing something like this:
#!/usr/bin/sh
INFILE=myfile
TOT=0
cat ${INFILE} | while read X
do
TOT=$(echo scale=8; ${TOT} + ${X} | bc)
done
echo "Total = ${TOT}"
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.
#!/usr/bin/sh
INFILE=myfile
TOT=0
bc |&
print -p "scale=8"
cat ${INFILE} | while read X
do
print -p "${TOT} + ${X}"
read -p TOT
done
print -p "quit"
echo "Total = ${TOT}"
You could improve this still further by using a register and simply adding to it:
e.g. print -p "a+=${X}"
I think you will be amazed at how well this will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 01:13 PM
08-26-2003 01:13 PM
Re: Very large numbers in a script
Here's my still better version taking advantage of a bc register; in this case 'a'.
#!/usr/bin/sh
INFILE=myfile
bc |&
print -p "scale=8;a=0"
cat ${INFILE} | while read X
do
print -p "a+= ${X}"
done
print -p "a"
read -p TOT
print -p "quit"
echo "Total = ${TOT}"
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.
Regards (and it ain't always Perl), Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2003 01:31 PM
08-26-2003 01:31 PM
Re: Very large numbers in a script
Thanks,
Steve