Re: function without arithematic operator
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Wed, 03 Aug 2005 00:11:30 GMT
Kenneth Brody wrote:
>
> rahul8143@xxxxxxxxx wrote:
> >
> > hello,
> > Is it possible to write a math library function sqrt in C without
> > arithmatic operators(*,+)?
> > can anyone give me hints to do that?
>
> Use division and subtraction instead. :-)
>
> Of course, there are only two reasons to do so that I can think of:
>
> (1) A nonsensical homework assignment.
> (2) A troll.
#include <errno.h>
#include <math.h>
double sqrt(double x)
{
if (x > 0) {
const double a = x;
double b = a / 2 - -0.5;
do {
x = b;
b = (a / x - -x) / 2;
} while (x > b);
} else {
if (0 > x) {
errno = EDOM;
x = -HUGE_VAL;
}
}
return x;
}
--
pete
.
- References:
- function without arithematic operator
- From: rahul8143
- Re: function without arithematic operator
- From: Kenneth Brody
- function without arithematic operator
- Prev by Date: Re: atrcmp and ==
- Next by Date: Re: can i run linux code on windows
- Previous by thread: Re: function without arithematic operator
- Next by thread: Re: function without arithematic operator
- Index(es):
Relevant Pages
|