calculator bc - scientific comandline-calculator

Mathematical tools, physics simulators, CAD, CNC, etc.
Post Reply
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

calculator bc - scientific comandline-calculator

#1 Post by MU »

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

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#2 Post by GuestToo »

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)

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#3 Post by MU »

oh, I did not check that :oops:
Mark

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#4 Post by BarryK »

dc is already in puppy.
comes with busybox.

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#5 Post by GuestToo »

dc is already in puppy.
comes with busybox.
yes, i know that .. but this is the FULL version, there is a difference

i like DC because it reminds me of HP calculators and Forth

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#6 Post by BarryK »

Ah yes, I bought an HP-45 when I was a student.
I was the only one in the class with a electronic calculator.
Before that I used a slide rule.

postfs1

#7 Post by postfs1 »

PI Image

Code: Select all

printf "%.9f\n" "`Calculator="103993/33102" ; echo "scale=10; $Calculator"|bc`"
Edit:

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.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#8 Post by L18L »

postfs1 wrote:PI Image

Code: Select all

printf "%.9f\n" "`Calculator="103993/33102" ; echo "scale=10; $Calculator"|bc`"
:roll: :?: :?: :?: :?: :roll:
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
#
:wink:

---------------------------------------
edit
Note, my post was not about precision of PI but only demonstrating a calculation without error messages :wink:
Last edited by L18L on Thu 09 Aug 2012, 20:13, edited 1 time in total.

Burunduk
Posts: 80
Joined: Sun 21 Aug 2011, 21:44

#9 Post by Burunduk »

https://en.wikipedia.org/wiki/Bc_progra ... 000_places

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...

postfs1

#10 Post by postfs1 »

Image

Code: Select all

printf "%.9f\n" "`echo -e 'scale\nscale=20\n4*a(1)'|bc -l`"
!ATTENTION! ===>
http://en.wikipedia.org/wiki/Rounding#R ... ven_method

Code: Select all

printf "%.1f\n" "74.35"
Gives: 74.3
Sometimes must be: 74.3
Sometimes must be: 74.4 #Round half to even

Code: Select all

printf "%.1f\n" "74.25"
Gives: 74.2
Sometimes must be: 74.2 #Round half to even
Sometimes must be: 74.3

ImageImageImageImageImage

http://brskari.wordpress.com/2011/04/23 ... ues-in-bc/

Burunduk
Posts: 80
Joined: Sun 21 Aug 2011, 21:44

#11 Post by Burunduk »

Lots of functions here: http://phodd.net/gnu-bc/

Download funcs.bc

Code: Select all

echo "round(4.35,.1)" | bc -l /path/to/funcs.bc
Results in 4.4 (round half up)

-----
L18L's console wrote:bash: printf: 3.1415926530: invalid number
3.14 is invalid number... in Germany (for printf but not for bc): 3,14 or LANG=C ist gut!

postfs1

#12 Post by postfs1 »

Image

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

postfs1

#13 Post by postfs1 »

Install_functions_for_Calculator--bc.sh

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
Edit: 2012, aug 18.
Theme(not a question): "Round half to even" rounding, isn't it?
9970/1048576=.01

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
Edit: 2012, aug 11.
PI=3.14

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
  #
 #
#
Edit: 2012, aug 11.
A script's content can be copied into text editor by means of <Quote> mode.

Post Reply