Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

square root function in embedded system using C

Status
Not open for further replies.

mohamed.elsabagh

Full Member level 2
Joined
Oct 27, 2010
Messages
145
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
Activity points
2,320
i need a function in embedded c to calculate square root of a number using microcontroller
 

What compiler are you using?
Most compilers come with a math library.
Look in the include directory of the compiler for 'math.h'
 
i need a function in embedded c to calculate square root of a number using microcontroller
If your compiler uses math.h then sqrt() is the function you need.

**broken link removed**
http://www.java2s.com/Code/C/math.h/sqrtreturnsthesquarerootofnum.htm
http://www.codecogs.com/reference/computing/c/math.h/sqrt.php

But are you sure about it? Because normally math.h is to be avoided in embedded systems because of execution time and code size produced by it. Especially if you take under consideration that this function takes a double as argument. You could also take a look at the below reference, where the author presents a couple of fast algorithms to calculate the square root of an integer.

http://www.codecodex.com/wiki/Calculate_an_integer_square_root

Hope this helps,
Alexandros
 
Sometimes you can 'cheat' and just store a look-up table ; ) It's fast but consumes ROM of course.
I once wanted to draw arbitrary circles on an LCD and given the dimensions of the LCD, my lookup
table was acceptable, because I knew that only circles or arcs up to a certain dimension could be drawn on the LCD.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top