Added sqrtf

This commit is contained in:
Alex 2022-12-29 02:05:51 +02:00
parent c04c544470
commit 42e10dc2b1
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 22 additions and 0 deletions

View File

@ -642,6 +642,24 @@ char *reverse(char *Buffer, int i, int j)
return Buffer; return Buffer;
} }
float sqrtf(float x)
{
if (x < 0.0f)
return NAN;
if (x < 1e-7f)
return 0.0f;
float guess = x / 2.0f;
for (short i = 0; i < 10; i++)
{
if (guess == 0.0f)
return 0.0f;
guess = (guess + x / guess) / 2.0f;
}
return guess;
}
char *strtok(char *src, const char *delim) char *strtok(char *src, const char *delim)
{ {
static char *src1; static char *src1;

View File

@ -5,6 +5,8 @@
extern "C" extern "C"
{ {
#endif #endif
#define NAN (__builtin_nanf(""))
int isdigit(int c); int isdigit(int c);
int isspace(int c); int isspace(int c);
int isempty(char *str); int isempty(char *str);
@ -15,6 +17,8 @@ extern "C"
void swap(char *x, char *y); void swap(char *x, char *y);
char *reverse(char *Buffer, int i, int j); char *reverse(char *Buffer, int i, int j);
float sqrtf(float x);
void backspace(char s[]); void backspace(char s[]);
void append(char s[], char n); void append(char s[], char n);