blob: a14970ad80e1c37a9da425749756684bc06ec807 [file] [log] [blame]
/*
* Copyright (c) 2018 Vikrant More
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <math.h>
#define MINDIFF 2.25e-308
float sqrtf(float square)
{
float root, last, diff;
root = square / 3.0;
if (square <= 0) {
return 0;
}
do {
last = root;
root = (root + square / root) / 2.0;
diff = root - last;
} while (diff > MINDIFF || diff < -MINDIFF);
return root;
}