Welcome to the most active Linux Forum on the web.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org bc and exponents containing decimals and fractions.
 User Name Remember Me? Password
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 09-15-2009, 12:52 AM #1 Dogs Member   Registered: Aug 2009 Location: Houston Distribution: Slackware 13.37 x64 Posts: 105 Rep: 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.
 09-15-2009, 08:47 AM #2 estabroo Senior Member   Registered: Jun 2008 Distribution: debian, ubuntu, sidux Posts: 1,117 Blog Entries: 2 Rep: 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
09-15-2009, 05:56 PM   #3
Dogs
Member

Registered: Aug 2009
Location: Houston
Distribution: Slackware 13.37 x64
Posts: 105

Original Poster
Rep:
Quote:
 Originally Posted by estabroo 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.

 09-15-2009, 10:13 PM #4 jlinkels Senior Member   Registered: Oct 2003 Location: Bonaire Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE Posts: 4,497 Rep: I wonder what you kids learn in school nowadays. x=a^^b ln(x)=ln(a^^b) ln(x)=b*ln(a) exp(ln(x))=exp(b*ln(a)) x=(exp(b*ln(a)) and of course this works in lc as well: Code: ```echo "e(4.7*l(2))" | bc -l 25.99207668339953672244``` jlinkels
09-15-2009, 10:55 PM   #5
gmbastos
LQ Newbie

Registered: Apr 2007
Location: Brazil
Distribution: Slackware
Posts: 21

Rep:
Quote:
 Originally Posted by jlinkels I wonder what you kids learn in school nowadays. x=a^^b ln(x)=ln(a^^b) ln(x)=b*ln(a) exp(ln(x))=exp(b*ln(a)) x=(exp(b*ln(a)) and of course this works in lc as well: 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... :(

 09-16-2009, 03:59 AM #6 jlinkels Senior Member   Registered: Oct 2003 Location: Bonaire Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE Posts: 4,497 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) jlinkels
03-12-2013, 04:27 PM   #7
sxdw
LQ Newbie

Registered: Jul 2011
Posts: 2

Rep:
Quote:
 Originally Posted by jlinkels I wonder what you kids learn in school nowadays. x=a^^b ln(x)=ln(a^^b) ln(x)=b*ln(a) exp(ln(x))=exp(b*ln(a)) x=(exp(b*ln(a)) and of course this works in lc as well: Code: ```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...

 Thread Tools Search this Thread Search this Thread: Advanced Search

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post R00T.OSIRIS Linux - General 1 04-21-2007 11:06 PM jabka Programming 12 12-16-2006 06:05 PM jabka Programming 7 11-20-2006 03:06 PM qwijibow Programming 3 02-20-2005 02:38 AM champ Programming 2 08-11-2004 12:07 AM

All times are GMT -5. The time now is 12:28 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -
 Advertisement
 My LQ
 Write for LQ LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
 Syndicate Latest Threads   LQ News Twitter: @linuxquestions Facebook: linuxquestions Google+: linuxquestions