![]() |
|
#1
|
|||
|
|||
Floating point math on bash command lineFor quick calculations I can do this on the linux command line:
Code:
Code:
I have seen that I can use bc (which is a powerful and very easy to use) : Code:
|
|||
|
#2
|
|||
|
|||
Re: floating point math on bash command lineQuote:
No. Regards, Dave Footnote: I'm thinking that bc is probably the "most popular" way, but you could also use GNU octave from bash (or other shell): Code:
|
|
#3
|
|||
|
|||
Re: Floating point math on bash command lineAhh yes octave.
wow Code:
Now I wonder what a(1) is... and 4* ??? man bc: MATH LIBRARY a (x) The arctangent of x, arctangent returns radians. boy I'm gonna have to get out a math book... Thanks dave |
|
#4
|
|||
|
|||
Re: Floating point math on bash command lineQuote:
Quote:
Refresh me: What the heck did I say back in December? (I mean, last Tuesday is ancient history to me; last December? Oh, man...) Here's what I say now: 22/7 is an infinitely repeating decimal fraction. If you round off 22/7 to four significant decimal digits you get 3.143 If you round off pi to four significant decimal digits you get 3.142 If you round off 22/7 to three significant digits you get 3.14 If you round off pi to three significant digits you get 3.14 My conclusion is that 22/7 is an approximation to pi that is correct to three significant decimal digits. Quote:
Here's the reasoning behind that little jewel: The arctangent function returns an angle whose tangent is given by the argument. In fact there are an infinite number of angles whose tangent is a given value. Most program implementations of the atan function return a value between -pi/2 and pi/2. See, for example Inverse Tangent Anyhow... The tangent of pi/4 radians is 1 Therefore the arctangent of 1 is pi/4 Therefore, pi is equal to 4 times the arctangent of 1. Of course, the arctangent function calculates an approximate value using whatever precision is available, so an approximation of pi can be obtained by multiplying arctangent(1) by four. Note that there is slight difference (two units in the 21st decimal digit) between pi and the approximation calculated by (4 times arctangent(1)). This is due to roundoff error/truncation error in the arctangent function evaluation being propagated to the product. Regards, Dave |
|
#5
|
||||
|
||||
Re: Floating point math on bash command lineQuote:
Quote:
re: octave Yes, Thanks for the example. I was getting into it and then it got cold! ("what the heck?" you say) Short story , This is an old farm house, we are using a wood stove exclusively. My fedora box is in the "Outback". I shut the door a few months ago and used the my old laptop with linuxfromscratch in a warm room. I didn't want to fool with building all the stuff for octave.... Now I'm back in here, but so many things to do... I did build tlc and tk and learned to make a graphical plotting program though!!!: ) Very interesting to use tlc and see what the pro's do with object oriented programming. Quote:
This would be that "bank" quality numeric handling you have talked about in the past. re: a (x) What you explain makes sense and I almost understand. What I really need to do in that department is start back at algebra and trig 1 and learn math! I find I understand it better now than in high school ,, but still , a long way to go. Thanks, Howard(); |
|
#6
|
|||
|
|||
Re: Floating point math on bash command lineQuote:
In that thread I said that 22/7 was correct to 3 significant decimal digits. What makes you say that your results are "not as close" as what I said? Quote:
Quote:
Decimal arithmetic is available natively in COBOL, and I know that there are BCD class libraries for C++. Or---you can roll your own arbitrary precision decimal arithmetic package. How tough could that be for people who build Linux from scratch? Regards, Dave |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic 2 dimensional array problem | mas287 | C Programming Language | 8 | 11-Feb-2009 18:06 |
| Need a function to make chart | branpute | C Programming Language | 10 | 03-Jan-2009 16:39 |
| No type named | nostaque | C++ Forum | 2 | 06-Nov-2008 16:46 |
| How to exchange the Lower and Upper Nibbles of a floating point number | vicky_brsh | C++ Forum | 2 | 15-May-2008 10:18 |
| Linked list: Dereferencing to incomplete type | shalombi | C Programming Language | 3 | 08-Jun-2007 15:47 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The