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.

how could i use the square root operation in the TC++

Status
Not open for further replies.
if there is no function which your compiler supports as sqrt() then try to write that function by yourself such as

for i++ ....

//check variable with i*i
if > then try for adding real value btw 0≈1

hard way..
 

I don't know whether there is a function for squareroot in TC++, but instead I will inform you about a really simple way to write your own squareroot function. There are many algorithms to find the squareroot of a number, the simplest being the Newton's iteration method:

6_1216649149.gif


where n is the number whose squareroot would be found, and x0 = 1. So, let's say we will find the squareroot of 2.

First iteration: x1 = 1.5 (not even close)
Second iteration: x2 = 1.41667 (at least we are going somewhere)
Third iteration: x3 = 1.41422 (hmm, really close)

You can go as many iteration as you want (though I think 5 at most is enough, 3 will do a good job), it depends how accurate you want the result, and what are your system requirements.
 

TC++ help file

<math.h>
sqrt, sqrtf, sqrtl
double sqrt(double x);
float sqrt(float x); [C++ only]
long double sqrt(long double x); [C++ only]
float sqrtf(float x); [required with C99]
long double sqrtl(long double x); [required with C99]
The function returns the real square root of x, x^(1/2). A domain error occurs if x < 0.
 

coz we were asked to make a simple program usin TC++ that shall compute values using Quadratic Eq'n..

i've tried
sqrt();
sqrt((b*b)-(4*a*c);

do you think my compiler does not really support sqrt.. or is it just my prog that i hav 2 work on

thnx ^_^
 

zurgh said:
coz we were asked to make a simple program usin TC++ that shall compute values using Quadratic Eq'n..

i've tried
sqrt();
sqrt((b*b)-(4*a*c);

do you think my compiler does not really support sqrt.. or is it just my prog that i hav 2 work on

thnx ^_^

if the value of sqrt((b*b)-(4*a*c) is negative then it ll stop.
 

    zurgh

    Points: 2
    Helpful Answer Positive Rating
i guess.. in a usual or common quadratic eq'n.. it is the 1st and last term that has the larger value.. is it? in that case a negative value shall stop my sqrt prog.. how can i correct that??
 

zurgh said:
i guess.. in a usual or common quadratic eq'n.. it is the 1st and last term that has the larger value.. is it? in that case a negative value shall stop my sqrt prog.. how can i correct that??

assign ((b*b)-(4*a*c)) to a variable and check it for negativity (<0) if its negative then prompt user such as 'undefined roots'

good luck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top