Пример #1
0
int				ft_ten_pow(int ten, int p)
{
	if (p <= 0)
		return (1);
	else
		return (ft_ten_pow(ten, p - 1) * 10);
}
Пример #2
0
double			ft_atod(char *s)
{
	int			i;
	int			j;
	double		integer;
	double		deci;

	i = 0;
	deci = 0.0;
	while (s[i] && s[i] != '.')
		i++;
	if (s[i] == '\0')
		return ((double)(ft_atoi(s)));
	else if (s[i] == '.')
	{
		integer = (double)ft_atoi(ft_strsub(s, 0, i));
		deci = (double)ft_atoi(ft_strsub(s, i + 1, ft_strlen(s) - i - 1));
		j = i + 1;
		while (ft_isdigit(s[j]) == 1)
			j++;
		deci = deci / ft_ten_pow(1, j - i - 1);
		deci = deci + integer;
	}
	return (deci);
}
Пример #3
0
double			ft_atod(const char *s)
{
	int			i;
	double		intger;
	double		flot_;

	i = 0;
	while (s[i] && s[i] != '.')
		i++;
	if (s[i] == '\0')
		return ((double)(ft_atoi(s)));
	else if (s[i] == '.')
	{
		intger = (double)ft_atoi(ft_strsub(s, 0, i));
		flot_ = (double)ft_atoi(ft_strsub(s, i + 1, ft_strlen(s) - i - 1));
		flot_ = flot_ / ft_ten_pow(1, ft_strlen(s) - i - 1);
		flot_ = flot_ + intger;
	}
	return (flot_);
}