bc and exponents containing decimals and fractions.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
bc and exponents containing decimals and fractions.
I need bc to allow me to use expressions such as 2^4.7
Currently, I get the error "Runtime warning (func=(main), adr=9): non-zero scale in exponent"
I downloaded the source awhile ago and located the error message, but I'm unsure as to how to phrase it so it will actually work.
I need this to work for my math class I'm in. Any help would be appreciated, and any help that would allow me to understand more about how this process works would be even moreso appreciated.
use octave instead, I'm guessing it would require serious changes to get bc to do decimal/fractional exponents
octave:1> 2^4
ans = 16
octave:2> 2^4.7
ans = 25.992
octave:3> 2^(2/3)
ans = 1.5874
Hey, thanks a lot. I'll give Octave a try and report back. I still want to change bc, though, as my main focus right now is being a darn good programmer. Part of this shall include ridiculous and unnecessary challenges, like adding functionality to bc through it's source code.
echo "e(4.7*l(2))" | bc -l
25.99207668339953672244
jlinkels
Good point, jlinkels, but remember it looses some precision due to introducing more rounding off.
One possible workaround would be to increase precision by two digits, performing the calculation and rounding back to the desired precision (still looses precision due to rounding but way less).
p.s.: don't trust that much in high school curriculum: there is much more distraction for kids nowadays (TV and internet for instance...).
Last edited by gmbastos; 09-15-2009 at 10:56 PM.
Reason: misspelled nickname... :(
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
I assume (but not sure) that ln and exp are calculated internally as Taylor series. I also think that the a^^b is calculated as Taylor series. That means in the first case two Taylor approximations and in the second case only one.
The question is how many Taylor terms are being used and how fast the series converge for ln, exp and ^^. The so called rest term of an n-length Taylor can be calculated. And how this is realated to the internal precision of bc.
Though the question is academic, it would be nice to look into that (by someone who has more time available than me)
echo "e(4.7*l(2))" | bc -l
25.99207668339953672244
jlinkels
A calculator is supposed to solve expressions. You are not supposed to make life easier for the calculator, it is supposed to be the other way around...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.