@Raghavan: What is wrong with
return sqrt((double)num);
Since most CPUs have square root instructions, and a square root takes
about the same time as a division, how can you hope to be any faster
with software?
Dave
On Aug 30, 1:07 am, Raghavan wrote:
> how to design this logic effectively?
>
@rajeev kumar
in babylonian method.. initial approx shud be an over estimate of ur square
root??
u taking it as 2..
isn't a wrong assumption?
On Tue, Aug 30, 2011 at 9:36 PM, aditya kumar
wrote:
> let u have to find the square root of s .
> a=sqrt(s) ;
> a^2=s ;
> 2(a^a)=s+a^2 ;
> a=(s+a^2)/2
let u have to find the square root of s .
a=sqrt(s) ;
a^2=s ;
2(a^a)=s+a^2 ;
a=(s+a^2)/2a ;
after 20th iteration you will get more approximated value .
hopefully it will help .:)
On Tue, Aug 30, 2011 at 9:14 PM, teja bala wrote:
> @aditya kumar
> Will u plz explain the logic involved here...?
>
@aditya kumar
Will u plz explain the logic involved here...?
On Tue, Aug 30, 2011 at 7:40 PM, aditya kumar
wrote:
> void getSquareRoot(float s)
> {
> float a=s;
> int i=0;
> for(i=0;i<20;i++)
> {
> a=(s+a*a)/(2*a);
> }
> printf("square root is %f",a);
> }
>
> On Tue, Aug 30, 2011 at
This code takes advantage of IEEE format of floating point numbers to
get a close approximation. Then two iterations of Newton's method get
about 12 digits of accuracy.
Don
float sqrt(float z) {
union
{
int tmp;
float f;
} u;
u.f = z;
u.tmp -= 1<<23;
u.tmp
void getSquareRoot(float s)
{
float a=s;
int i=0;
for(i=0;i<20;i++)
{
a=(s+a*a)/(2*a);
}
printf("square root is %f",a);
}
On Tue, Aug 30, 2011 at 6:00 PM, Sanjay Rajpal wrote:
> Binary Search kind of mathod is useful here :
>
> float SquareRoot(float n,float start,float end)
> {
> fl
Binary Search kind of mathod is useful here :
float SquareRoot(float n,float start,float end)
{
float s=(start+end)/2;
if(n - sqr(s) < 0.001) && (n - sqr(s) > -0.001))
return (end+start)/2;
else if(sqr(s) > n)
return SquareRoot(n,0.0,s);
else
return SquareRoot(n,s,end);
}
Sanju
:
Anyone interested in laying out the trade off's of the Babylonian method vs
Newton Raphson?
--
Anup Ghatage
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from
newton raphson will do it.. :)
On Tue, Aug 30, 2011 at 3:55 PM, UTKARSH SRIVASTAV
wrote:
> i don't whethe you have studied a subject cbnst from that use newton
> raphson method
>
>
> On Tue, Aug 30, 2011 at 2:39 AM, Ankuj Gupta wrote:
>
>> U can use binary search method
>>
>> On Aug 30, 1:56 pm,
i don't whethe you have studied a subject cbnst from that use newton raphson
method
On Tue, Aug 30, 2011 at 2:39 AM, Ankuj Gupta wrote:
> U can use binary search method
>
> On Aug 30, 1:56 pm, Rajeev Kumar wrote:
> > use Babylonian method(Efficient) algrithm..
> > Refer :
> http://e
U can use binary search method
On Aug 30, 1:56 pm, Rajeev Kumar wrote:
> use Babylonian method(Efficient) algrithm..
> Refer
> :http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylo...
>
> public *void* getSquareRoot(double s) {
> double Xn = 2.0;
> double lastXn
11 matches
Mail list logo