OT: bc
Brian K. White
brian at aljex.com
Fri Jan 20 21:55:32 PST 2006
----- Original Message -----
From: "John Esak" <john at valar.com>
To: "Fplist (E-mail)" <filepro-list at seaslug.org>
Sent: Friday, January 20, 2006 11:20 PM
Subject: RE: OT: bc
>> | I like to check figures in filePro with bc and it's impossible.
>> I've scanned
>> | the man page, of course, but didn't see anything about rounding.
>>
>> Doesn't your 'bc' man page say what mine does, i.e.:
>>
>> In every case where digits are discarded truncation is performed
>> without rounding.
>>
>> --
>> JP
>
> JP,
>
> Are you being serious. Of course, I saw this... how in the hell does that
> help with my question of "How do you *get* bc to round like filePro and
> every other computer application I've ever seen.... The bc program can do
> miracles, it has while loops, in-bases, out-bases... more *stuff* than
> could
> ever be believed. Are you trying to tell me that you are not surprised
> that
> bc can't "round"?? I'll tell you... this program was written by one hell
> of
> a nerd whoever he is.... someone who can program in every math function
> known to man, but somehow just loses the ability to use the program with
> "money". There is no program in the world that deals with money that
> truncates. They either round up or down, sometimes being electable. A
> math/numbers program that simply truncates and that's it... pretty
> amazing,
> I think.
Well there is this guy who made a boatload of functions, and there are a few
rounding functions, none of which looks especially handy if that's all you
want is to round a single value properly.
Used within some larger bc script they are probably pretty useful. the rnd()
function looks to be the closest to what you want, but it itself requires a
few of the other functions so it takes a lot of junk to get a rounded value.
http://www.cyreksoft.yorks.com/gnu-bc/funcs.bc
Looks like you need at least this in order to use rnd()
define int(x) { auto os;os=scale;scale=0;x/=1;scale=os;return(x) }
define floor(x) { auto xx;xx=int(x);if(xx>x)xx-=1;return(xx) }
define rnd(x,y) { return(y*floor(x/y+.5)) }
And, this may only work in GNU bc. You probably do have gnu bc in
/usr/gnu/bin/bc
You probably also already have a symlink "gbc" in /usr/gnu/bin, so if
/usr/gnu/bin is anywhere in your path, you only need to say |gbc in place of
|bc .
The web site also indicates you need to use bc -l (load arbitrary precision
library) with these. Maybe these particular functions don't need that but
only some of the many other functions in that file do. I can't tell.
Maybe there is a way to get these functions loaded automatically any time
you run bc, or maybe theres a not-too-cumbersome command line argument you
can add that loads a function library file, and still lets you pipe in on
stdin.
Or you could just use printf.
Brian K. White -- brian at aljex.com -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
More information about the Filepro-list
mailing list