?? atof.c
字號:
/* Functions to perform various conversions to and from single-precision */
/* floating point 2/ 8/00 E.M.Greene */
/* Adapted by rfm ImageCraft (see math2.c.save) */
/* Modified (slightly) to accept expressions without decimal point, 7th Jan 2001 A.L.E. */
#include <ctype.h>
#include <math.h>
float powi(int x, int y);
float atof(char *s)
{
float v = 0.0,
scale = 0.1;
char mneg = ' ',
eneg = ' ';
int e = 0;
while (isspace(*s))
s++;
if (*s == '-')
mneg = *s++;
else
if (*s == '+')
s++;
while (isdigit(*s))
v = 10.0 * v + *s++ - '0';
if (*s == '.')
s++;
while(isdigit(*s))
{
v += (*s++ - '0') * scale;
scale /= 10.0;
}
if (toupper(*s) == 'E')
{
s++;
if (*s == '-')
eneg = *s++;
else
if (*s == '+')
s++;
while (isdigit(*s))
e = 10 * e + *s++ - '0';
if (eneg == '-')
v = v / powi(10,e);
else
v = v * powi(10,e);
}
if (mneg == '-')
v = -v;
return v;
}
float powi(int x, int y)
// Determines x-raised-to-the-power-of-y and returns the
// result as a float
{
int d;
float p = 1;
for (d = 0; d < y; d++)
p *= x;
return p;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -