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.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

Click Here to receive this Complete Guide absolutely free.

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

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.