Metro-Siberia-4/src/tools.c

52 lines
1.4 KiB
C

/*
* Metro Siberia 4 - A sequel to Dark Storm's Metro Siberia 3 for CASIO calculators.
* Copyright (C) 2015 Dark Storm
* Copyright (C) 2022 Mibi88
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
#include "includes.h"
char* _itoa(int i, char b[])
{
char const digit[] = "0123456789";
char* p = b;
if(i<0){
*p++ = '-';
i *= -1;
}
int shifter = i;
do{ //Move to where representation ends
++p;
shifter = shifter/10;
}while(shifter);
*p = '\0';
do{ //Move back, inserting digits as u go
*--p = digit[i%10];
i = i/10;
}while(i);
return b;
}
#define PI 3.14159
#define M_PI_4 0.78539
#define FABS(x) ((x<0)?-x:x)
float _atan(float x)
{
return (x * (M_PI_4 - ((FABS(x) - 1) * (0.2447 + 0.0663 * FABS(x)))));
}