DECIMAL NUMBER ARITHMATIC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DECIMAL NUMBER ARITHMATIC

2,669 Views
tballer
Contributor I
I am new to this and am trying to do arithmetic on a decimal number in the following format:
XXX.XXXXXX

The arithmetic will include squaring, taking the square root, dividing and addition and subtraction.  What is the best way to go about this?
Labels (1)
0 Kudos
5 Replies

690 Views
JimDon
Senior Contributor III
Depends on what you consider "best".

The easiest way it to use doubles.

0 Kudos

690 Views
tballer
Contributor I
Is it easy then to square a number, lets say 128.3434434, and put it in memory in a 16 bit microcontroller?
0 Kudos

690 Views
nikosxan
Contributor I
Using a C compiler for the specific MCU you use will enable you to have variables of float types and supportes also math (multiplication / division / root, even some trigonometry). Also when having variables and a C language enviroment is no problme 'store results' in memory.... However all these ends up with a lot of  code size increase, since float math nedds a lot of code to be implemented, but this should be no major problem if you have decent FLASH memory (eg 64 K or more...). Also, MCUs support integer math internally and up to multiplication / division, so doing a sqrt or a sine is also time consuming compared to sipler 8 / 16 bits math.
 
What's the need for doing such math ?
0 Kudos

690 Views
nikosxan
Contributor I
...Cont...
 
If you really need do complex math (as float numbers support, sin / cosine, sqrt etc)  the only way to go is use a high level language (mostly C for microcontroller, but also Basic or even pascal could be found)...
0 Kudos

690 Views
JimDon
Senior Contributor III

You will need to learn the "C" programming language, but yes it is.


0 Kudos