0
Square root without math.h
Hey SoloLearners! I was wondering if there is a way to calculate the square root of a given number(int or float) without prepared methods like sqrt() in C. I have an assignment in university that requires me to calculate the area of the triangle that is created by user input coordinates, without using math.h in C.
5 Antworten
+ 7
MarJan you need sqrt if you don't know height https://en.m.wikipedia.org/wiki/Heron%27s_formula
+ 5
https://en.m.wikipedia.org/wiki/Methods_of_computing_square_roots
+ 5
Moji 99 Using Intel instruction set -- so called intrinsics -- you'd be able to do floating-point inverse square root.
[https://en.wikipedia.org/wiki/Fast_inverse_square_root]
Line 224 to 348 for detailed explanation.
https://code.sololearn.com/cSDEjCsGVKz7/?ref=app
don't forget to add #include <x86intrin.h> at the top of your code.
+ 1
I don't see why would you use sqrt() here. You have a lot of formulas to calculate the are of a triangle e.g. Area = 1/2 * Base * Height
+ 1
Mert Yazıcı, I know that :D
What I meant was that there are a lot of formulas, and You can find the height when you know coordinate of every vertex in a triangle