- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: bc and rounding ...
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
Discussions
Discussions
Forums
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
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
тАО05-15-2006 07:44 AM
тАО05-15-2006 07:44 AM
I'd like to generate some general discussion about mathematics in HP-UX from the shell, starting with:
- How does one do rounding in "bc"?
- Does anyone know where I could find the "bc tutorial in Number Processing Users Guide" referenced in the bc man page?
- Is there a good beginners' reference for dc?
- Do either of the above calculate standard deviation, solving matrices, or other interesting math/statistics? (Deliberately left wide open!)
(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.)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2006 09:06 AM
тАО05-15-2006 09:06 AM
SolutionUnfortunately, 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
It is even tricky to locate on the net...here are some references:
http://www.unixprogram.com/bc.pdf
http://www.answers.com/topic/bc-programming-language
There are some GNU bc manuals...much of it will apply, but as with most GNU tools, there are enhancements...
http://www.numbertheory.org/gnubc/gnubc.html
and for dc
http://en.wikipedia.org/wiki/Dc_(Unix)
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2006 09:54 AM
тАО05-15-2006 09:54 AM
Re: bc and rounding ...
define r (a,s) {
auto z,f,n
n = 0;
z=scale;
scale=s+1;
if (a < 0) { n = 1; a = -(a) }
f=a + (5 / 10^(s + 1));
scale=s;
f=(f * (10^s)) / (10^s);
if (n > 0) f = -(f);
scale=z;
return(f)
}
a=r(4.976,2)
a
4.98
You send in the value and the number of desired decimal places. Note that the rounding assumes a radix of 10.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 05:37 AM
тАО05-22-2006 05:37 AM
Re: bc and rounding ...
"BC is a language and a compiler for doing arbitrary precision arithmetic on the PDP-11
under the UNIX├в time-sharing system."
I'm loving it. Handed down with the monolith from 2001 ...
I was hoping there would be some built-in functions; I guess there are not so many as I had hoped.
Anyone else? No mathomatic folks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 06:09 AM
тАО05-22-2006 06:09 AM
Re: bc and rounding ...
Perl's POSIX module (part of its standard distribution) offers the 'floor' and 'ceil' functions in addition ot 'int' for rounding.
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.
use POSIX qw(floor, ceil);
Regards!
...JRF...