| | |
Square root program without sqrt or pwr
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>is there any way one could do a square root program without sqrt or pwr functions?
No, those functions are magic. There's no way you can simulate their behavior in C++ without pixie dust or phoenix feathers. One might assume that if you know how the mathematics work, you could come up with a sensible facsimile, but in reality, only compiler writers are capable of creating such things...
No, those functions are magic. There's no way you can simulate their behavior in C++ without pixie dust or phoenix feathers. One might assume that if you know how the mathematics work, you could come up with a sensible facsimile, but in reality, only compiler writers are capable of creating such things...
I'm here to prove you wrong.
lol, point me out to these threads if you can, just in case i can point them out lol
anyways, the teacher wants us to write a program without relying on these special functions. I can do them with, but now he wants us to do without.
I do not know of any mathematical formula that will enable me to achieve this without using a square root.
I will ask him, to clarify. Will post back later.
anyways, the teacher wants us to write a program without relying on these special functions. I can do them with, but now he wants us to do without.
I do not know of any mathematical formula that will enable me to achieve this without using a square root.
I will ask him, to clarify. Will post back later.
>anyways, the teacher wants us to write a program without relying on these special functions.
Yea, we figured as much. The thing is, there's no point to it if the functions are available. That's why they're there, so you don't have to write them. Anyway, a simple pow is easy to write: Just multiply x with itself y times and you have
. sqrt is harder, but you can find examples and explanations all over the web. Most likely you don't care about efficiency for a class, so just pick the first one you find that works. Two relatively simple ones are binary search (like Rashakil suggested) and newton iteration.
Yea, we figured as much. The thing is, there's no point to it if the functions are available. That's why they're there, so you don't have to write them. Anyway, a simple pow is easy to write: Just multiply x with itself y times and you have
I'm here to prove you wrong.
heres one (I do not know what it is called. My friend and I were having a competition who could make the fastest sqrt algorithm, so this is mine):
c++ Syntax (Toggle Plain Text)
double sqrt(double num) { double mod=1; double c=0; for(int d=0; d<50; c+=mod, d++) if(c*c>num) { c-=mod; mod/=10; } return c; }
"Hey ass, don't hijack my thread. This is serious." -JoshSCH
Different methods of finding the square root.
> Try it with a few others as well where one is the square root of the other.
Yes, logarithmic method seems to be a good choice.
> Try it with a few others as well where one is the square root of the other.
Yes, logarithmic method seems to be a good choice.
Last edited by ~s.o.s~; Jun 6th, 2007 at 1:58 pm.
I don't accept change; I don't deserve to live.
![]() |
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







