Alg atof
#include <stdio.h>
#include <math.h>
int Reverse(int n)
{
int m=0;
for( ; n>0; n/=10 )
m = m*10 + (n%10);
return m;
}
bool IsNumber(char c)
{
return c>='0' && c<='9';
}
double Atof(const char *s, char **stopPos)
{
int sign = 1;
double l1 = 0.0;
double l2 = 0.0;
int sign2 = 1;
double r = 0.0;
// num = isNeg l * 10^r
if(*s=='+') s++;
if(*s=='-') {s++; sign = -1;}
for( ; IsNumber(*s); s++)
l1 = l1*10 + (*s-'0');
if(*s=='.')
{
s++;
double f=0.1;
for( ; IsNumber(*s); s++, f/=10)
l2 += (*s-'0')*f;
}
if(*s=='e')
{
s++;
if(*s=='+') s++;
if(*s=='-') {s++; sign2 = -1;}
for( ; IsNumber(*s); s++)
r = r*10 + (*s-'0');
}
*stopPos = s;
return sign*(l1+l2)*pow(10,sign2*r);
}
void main(int argc, char *argv[])
{
if(argc>1)
{
double r = Atof(argv[1]);
printf("%g\n", r);
}
}
#include <math.h>
int Reverse(int n)
{
int m=0;
for( ; n>0; n/=10 )
m = m*10 + (n%10);
return m;
}
bool IsNumber(char c)
{
return c>='0' && c<='9';
}
double Atof(const char *s, char **stopPos)
{
int sign = 1;
double l1 = 0.0;
double l2 = 0.0;
int sign2 = 1;
double r = 0.0;
// num = isNeg l * 10^r
if(*s=='+') s++;
if(*s=='-') {s++; sign = -1;}
for( ; IsNumber(*s); s++)
l1 = l1*10 + (*s-'0');
if(*s=='.')
{
s++;
double f=0.1;
for( ; IsNumber(*s); s++, f/=10)
l2 += (*s-'0')*f;
}
if(*s=='e')
{
s++;
if(*s=='+') s++;
if(*s=='-') {s++; sign2 = -1;}
for( ; IsNumber(*s); s++)
r = r*10 + (*s-'0');
}
*stopPos = s;
return sign*(l1+l2)*pow(10,sign2*r);
}
void main(int argc, char *argv[])
{
if(argc>1)
{
double r = Atof(argv[1]);
printf("%g\n", r);
}
}