how to make a square root function in c++ without stl

#include <iostream>

float squareRoot(float num);

int main() {
    float number;
    std::cout << "Enter a number: ";
    std::cin >> number;

    if (number < 0) {
        std::cout << "Square root is undefined for negative numbers." << std::endl;
    } else {
        float result = squareRoot(number);
        std::cout << "Square root of " << number << " is: " << result << std::endl;
    }

    return 0;
}

float squareRoot(float num) {
    float x = num;
    float y = 1;
    float epsilon = 0.000001; // Desired precision

    while (x - y > epsilon) {
        x = (x + y) / 2;
        y = num / x;
    }

    return x;
}