/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atof.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/17 21:19:17 by yantoine #+# #+# */ /* Updated: 2025/02/17 21:20:13 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ #include "miniRT.h" float ft_atof(char *str) { float res; float dec; int sign; res = 0; dec = 0; sign = 1; if (*str == '-') { sign = -1; str++; } while (*str >= '0' && *str <= '9') { res = res * 10 + *str - '0'; str++; } if (*str == '.') { str++; while (*str >= '0' && *str <= '9') { dec = dec * 10 + *str - '0'; str++; } } return (sign * (res + dec / pow(10, ft_strlen(str)))); }