calculator bc - scientific comandline-calculator
calculator bc - scientific comandline-calculator
This is a scientific comandline-calculator.
manual:
http://www.gnu.org/software/bc/manual/bc.html
You can run it from the dotpups-menu.
That opens a yellow xterm, simply enter
2+2
there.
Download (48 kb)
http://dotpups.de/dotpups/System_Utilit ... ulator.pup
It requires libreadline4, if you don't have it yet, get it here:
http://noforum.de/dotpups/libreadline-so-4.pup (82 kb)
Mark
manual:
http://www.gnu.org/software/bc/manual/bc.html
You can run it from the dotpups-menu.
That opens a yellow xterm, simply enter
2+2
there.
Download (48 kb)
http://dotpups.de/dotpups/System_Utilit ... ulator.pup
It requires libreadline4, if you don't have it yet, get it here:
http://noforum.de/dotpups/libreadline-so-4.pup (82 kb)
Mark
i have a BC and DC package on my dotpups page
* BC is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language.
* DC is a reverse-polish desk calculator which supports unlimited precision arithmetic. It also allows you to define and call macros.
now you have a choice of packages (but my package is just the command line utilities)
* BC is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language.
* DC is a reverse-polish desk calculator which supports unlimited precision arithmetic. It also allows you to define and call macros.
now you have a choice of packages (but my package is just the command line utilities)
PI
Edit:
Code: Select all
printf "%.9f\n" "`Calculator="103993/33102" ; echo "scale=10; $Calculator"|bc`"
Code: Select all
printf "%.9f\n" "`Calculator=\"103993/33102\" ; echo \"scale=10; $Calculator\"|bc`"
- Attachments
-
- value_of_PI--picture.png
- Quirky Linux - 1.40
- (88.3 KiB) Downloaded 631 times
Last edited by postfs1 on Wed 08 Aug 2012, 02:04, edited 2 times in total.
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
postfs1 wrote:PI
Code: Select all
printf "%.9f\n" "`Calculator="103993/33102" ; echo "scale=10; $Calculator"|bc`"
my console answered and wrote:bash: printf: 3.1415926530: invalid number
0,000000000
#
my console wrote:# echo "scale=10; 103993/33102" | bc
3.1415926530
#
# echo "scale=99; 103993/33102" | bc
3.141592653011902604072261494773729684007008639961331641592653011902604072261494773729684007008639961
#
---------------------------------------
edit
Note, my post was not about precision of PI but only demonstrating a calculation without error messages
Last edited by L18L on Thu 09 Aug 2012, 20:13, edited 1 time in total.
https://en.wikipedia.org/wiki/Bc_progra ... 000_places
-----
http://x-bc.sourceforge.net/extensions_bc.html
Code: Select all
echo "scale=100; 4*a(1)" | bc -l
http://x-bc.sourceforge.net/extensions_bc.html
- contains functions of trigonometry, exponential functions, functions of number theory and some mathematical constants...
Code: Select all
printf "%.9f\n" "`echo -e 'scale\nscale=20\n4*a(1)'|bc -l`"
http://en.wikipedia.org/wiki/Rounding#R ... ven_method
Code: Select all
printf "%.1f\n" "74.35"
Sometimes must be: 74.3
Sometimes must be: 74.4 #Round half to even
Code: Select all
printf "%.1f\n" "74.25"
Sometimes must be: 74.2 #Round half to even
Sometimes must be: 74.3
http://brskari.wordpress.com/2011/04/23 ... ues-in-bc/
Lots of functions here: http://phodd.net/gnu-bc/
Download funcs.bc
Results in 4.4 (round half up)
-----
Download funcs.bc
Code: Select all
echo "round(4.35,.1)" | bc -l /path/to/funcs.bc
-----
3.14 is invalid number... in Germany (for printf but not for bc): 3,14 or LANG=C ist gut!L18L's console wrote:bash: printf: 3.1415926530: invalid number
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Rounding ===>
echo 'round(1731.543534, .001)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1731.544
echo 'round(1731.548534, .001)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1731.549
echo 'round(1731.543534, 1)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1732
echo 'round(1732.543534, 1)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1733
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
echo 'round(1731.543534, .002)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1731.544
echo 'round(1731.548534, .002)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1731.548
echo 'round(1731.543534, 2)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1732
echo 'round(1732.548534, 2)'|bc -l /archive/Command_Line_Calculator--bc/code/funcs.bc
#OUTPUT: 1732
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Theme(not a question): "Round half to even" rounding, isn't it?Install_functions_for_Calculator--bc.shEdit: 2012, aug 18.Code: Select all
#!/bin/bash # #SRC: http://phodd.net/gnu-bc/phodd.net-gnu-bc-201206232000+pdb+html.zip # mkdir -p /usr/share/bc ; cd /usr/share/bc ; curl -C - -O file:///mnt/sr0/Y2012-M08-D09/Programs_for_Quirky-Linux-1.40/Packed_files/Command_Line_Calculator--bc/phodd.net-gnu-bc-201206232000+pdb+html.zip ; unzip -j phodd.net-gnu-bc-201206232000+pdb+html.zip code/funcs.bc ; rm /usr/share/bc/phodd.net-gnu-bc-201206232000+pdb+html.zip ; # # #RESULT: bc -l /usr/share/bc/funcs.bc
9970/1048576=.01Edit: 2012, aug 11.Code: Select all
echo 'round('"`echo "scale=25 ; 9970/1048576"|bc -l /usr/share/bc/funcs.bc|tee /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 25|sed "s/[0-46-9]/.000000000000000000000001/"|sed "s/5/.000000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 24|sed "s/[0-46-9]/.00000000000000000000001/"|sed "s/5/.00000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 23|sed "s/[0-46-9]/.0000000000000000000001/"|sed "s/5/.0000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 22|sed "s/[0-46-9]/.000000000000000000001/"|sed "s/5/.000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 21|sed "s/[0-46-9]/.00000000000000000001/"|sed "s/5/.00000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 20|sed "s/[0-46-9]/.0000000000000000001/"|sed "s/5/.0000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 19|sed "s/[0-46-9]/.000000000000000001/"|sed "s/5/.000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 18|sed "s/[0-46-9]/.00000000000000001/"|sed "s/5/.00000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 17|sed "s/[0-46-9]/.0000000000000001/"|sed "s/5/.0000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 16|sed "s/[0-46-9]/.000000000000001/"|sed "s/5/.000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 15|sed "s/[0-46-9]/.00000000000001/"|sed "s/5/.00000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 14|sed "s/[0-46-9]/.0000000000001/"|sed "s/5/.0000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 13|sed "s/[0-46-9]/.000000000001/"|sed "s/5/.000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 12|sed "s/[0-46-9]/.00000000001/"|sed "s/5/.00000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 11|sed "s/[0-46-9]/.0000000001/"|sed "s/5/.0000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 10|sed "s/[0-46-9]/.000000001/"|sed "s/5/.000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 9|sed "s/[0-46-9]/.00000001/"|sed "s/5/.00000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 8|sed "s/[0-46-9]/.0000001/"|sed "s/5/.0000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 7|sed "s/[0-46-9]/.000001/"|sed "s/5/.000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 6|sed "s/[0-46-9]/.00001/"|sed "s/5/.00002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 5|sed "s/[0-46-9]/.0001/"|sed "s/5/.0002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 4|sed "s/[0-46-9]/.001/"|sed "s/5/.002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 3|sed "s/[0-46-9]/.01/"|sed "s/5/.02/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; rm /var/tmp/.bc
A script's content can be copied into text editor by means of <Quote> mode.PI=3.14Edit: 2012, aug 11.Code: Select all
echo -n >/var/tmp/.bc ; echo 'round('"`echo -e "scale\nscale=26\n4*a(1)"|bc -l /usr/share/bc/funcs.bc|tail -n 1|tee /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 26|sed "s/[0-46-9]/.0000000000000000000000001/"|sed "s/5/.0000000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 25|sed "s/[0-46-9]/.000000000000000000000001/"|sed "s/5/.000000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 24|sed "s/[0-46-9]/.00000000000000000000001/"|sed "s/5/.00000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 23|sed "s/[0-46-9]/.0000000000000000000001/"|sed "s/5/.0000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 22|sed "s/[0-46-9]/.000000000000000000001/"|sed "s/5/.000000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 21|sed "s/[0-46-9]/.00000000000000000001/"|sed "s/5/.00000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 20|sed "s/[0-46-9]/.0000000000000000001/"|sed "s/5/.0000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 19|sed "s/[0-46-9]/.000000000000000001/"|sed "s/5/.000000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; # # # echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 18|sed "s/[0-46-9]/.00000000000000001/"|sed "s/5/.00000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 17|sed "s/[0-46-9]/.0000000000000001/"|sed "s/5/.0000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 16|sed "s/[0-46-9]/.000000000000001/"|sed "s/5/.000000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 15|sed "s/[0-46-9]/.00000000000001/"|sed "s/5/.00000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 14|sed "s/[0-46-9]/.0000000000001/"|sed "s/5/.0000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 13|sed "s/[0-46-9]/.000000000001/"|sed "s/5/.000000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 12|sed "s/[0-46-9]/.00000000001/"|sed "s/5/.00000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 11|sed "s/[0-46-9]/.0000000001/"|sed "s/5/.0000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; # # # echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 10|sed "s/[0-46-9]/.000000001/"|sed "s/5/.000000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 9|sed "s/[0-46-9]/.00000001/"|sed "s/5/.00000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 8|sed "s/[0-46-9]/.0000001/"|sed "s/5/.0000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 7|sed "s/[0-46-9]/.000001/"|sed "s/5/.000002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 6|sed "s/[0-46-9]/.00001/"|sed "s/5/.00002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 5|sed "s/[0-46-9]/.0001/"|sed "s/5/.0002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 4|sed "s/[0-46-9]/.001/"|sed "s/5/.002/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; echo 'round('"`cat /var/tmp/.bc`"', '"`cat /var/tmp/.bc|cut -d. -f2-|cut -c 3|sed "s/[0-46-9]/.01/"|sed "s/5/.02/"`"')' |bc -l /usr/share/bc/funcs.bc|cat|tee /var/tmp/.bc ; rm /var/tmp/.bc # # #