Hi to all,

I am new to this forum..If i did any thing wrong in this thread please correct me...

Let me tell you something about my project ....

I am working on ARM7-LPC2148 processor with Graphical LCD. Now i am making a calculator which should be like as our PC calculator...

I did in a normal way this calculations that means

The steps involved in my calculator are...

1. Taking input numbers as strings

2. converting them to float values by using atof() function which is having a
limitation to return floating value.

3. Doing all calculations in a normal way by using operators

egg: if(operator=='+')
result = a+b;

if(operator=='-')
result = a-b;

if(operator=='*')
result = a*b;

if(operator=='/')
result = a/b;

4. Then converting that result (floating value) to string format and then printing it on
GLCD screen.


By using double, long long unsigned int..data types i can store limited values and i
am unable to get the exact values ...and i am unable to do the big big calculations.

That's why i have chosen a path to calculate these type things by using Bit
manipulation method ...

i can do addition and subtraction by doing bit manipulations.But for multiplication and division i dont have the idea how our PC doing that much big calculations and giving accurate values...

Please help in this regard...

Why would you want to use bit manipulation to do the arithmetic? And how would you use bit manipulation on floats or doubles? Just using + - * / is as easy as it gets.

As for accuracy, what is the value of 1 divided by 3? And what is the digital (binary) equivalent of that exact value? What you will find is the exact value does not exist. Digital representations are inherently inaccurate. Close enough is as close as you can get.

And there limitations on the size of your values using a computer. 16 bits, 32 bits, 64 bits can only hold so much data.

16 bits, 32 bits, 64 bits can only hold so much data.

Thanks for giving quick reply...
yes sir you are absolutely wright we can't say the accurate value for 1/3...

Here my problem is...I am using a 32 bit controller so we can get the values as PC calculator..But i am not getting that much efficient calculations..

for egg:

tan 45=1 we can get this value accurately in PC calculator....

My controller takes the input for angles in radiens not in degrees. If i want to give the input in degrees I've to convert it into radiens format..Then i will get the value...In this process, i am converting this degree value to radiens like this..

radiens=degrees*(PI/180)

But with that value i can't get the exact result as PC calculator result...

So how can i sort it out...

Take one more example...

If i want to calculate below one

9999999999999999992323.12435/123456789633.45 i can't get the value because it is not possible to store that value in any data type available(i just thought like that..if we can store that much big value then please tell me...)

so this are the problems..please suggest me...

Since any value of PI you use is by definition inaccurate, you will never get an accurate result.

What value do you expect and what value do you get? Say for tan 45 you mentioned you were expecting 1. You didn't bother to tell us what you got so here are two possibilities:
1) If answer you got was 3 you have a problem with your equation.
2) If your answer was 0.9999999998 or 1.00000001 that's close enough in the computer world.

I'm a big fan of reinventing the wheel. And I'm also a huge fan of bit manipulation.

First of all, I agree that if you are making a calculator program you should prepare for numbers a computer may not be able to calculate with standard types. So a bit-level approach sounds great! Even with addition and subtraction, the bit approach would allow you to more efficiently add enormous numbers past the maxint 64 bit limit.

Therefore, to answer your initial question about bit-level multiplication and division, and perhaps other more complex operations such as powers and roots, you are asking the wrong forum and looking in the wrong place.

You need to read up on binary mathematics. It involves loops, shifts and carry operations -- I would suggest that if you want to tackle this project in C that you inline-asm your code or link an assembly function to your project, since this stuff you want to do is actually better suited for that language since type casting operations can be bypassed there and you can work off of CPU registers exclusively.

For a simple to program algorithm, try this:

http://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm
http://www.binarymath.info/multiplication-division.php

If you want an even faster algorithm, they are explained here in the section titled "Fast multiplication algorithms for large inputs":

http://en.wikipedia.org/wiki/Multiplication_algorithm

I hope that points you to the right direction. Good luck!

This article has been dead for over six months. Start a new discussion instead.