feat(math/sqrt): adding a function to calculate square root
This commit is contained in:
parent
c27526bc24
commit
62dec89863
1 changed files with 28 additions and 0 deletions
28
math/ft_sqrt.c
Normal file
28
math/ft_sqrt.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sqrt.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/17 16:30:27 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/17 16:37:00 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
uint64_t ft_sqrt(uint64_t nb)
|
||||||
|
{
|
||||||
|
uint64_t i;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while ((i * i) <= nb && i <= 4294967296)
|
||||||
|
{
|
||||||
|
if ((i * i) == nb)
|
||||||
|
return (i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue