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.

2nd Nov 2018, 1:34 PM
Moji 99
Moji 99 - avatar
5 Antworten
+ 7
MarJan you need sqrt if you don't know height https://en.m.wikipedia.org/wiki/Heron%27s_formula
2nd Nov 2018, 1:56 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 5
https://en.m.wikipedia.org/wiki/Methods_of_computing_square_roots
2nd Nov 2018, 1:46 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 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.
2nd Nov 2018, 1:57 PM
Babak
Babak - avatar
+ 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
2nd Nov 2018, 1:47 PM
MarJan
MarJan - avatar
+ 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
2nd Nov 2018, 2:17 PM
MarJan
MarJan - avatar