-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
42 lines (37 loc) · 1.54 KB
/
utils.py
File metadata and controls
42 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# **************************************************************************** #
# #
# ::: :::::::: #
# utils.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: cpieri <cpieri@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/09/17 20:44:50 by cpieri #+# #+# #
# Updated: 2019/12/13 14:16:54 by cpieri ### ########.fr #
# #
# **************************************************************************** #
import sys
import re
from color import Color
def ft_abs(nb):
if nb < 0:
nb = nb * -1
return nb
def get_int(power):
regex_int = r"((\s+)?(\+|\-)(\s+)?)?((\d+\.)?\d+)"
nb_of_power = re.sub(r"\s+", "", re.match(regex_int, power).group())
check_is_float = re.search(r"(\.)", nb_of_power)
nb_of_power = float(nb_of_power) if check_is_float else int(nb_of_power)
return nb_of_power
def ft_sqrt(nb):
if nb == 0 or nb == 1:
return nb
calc = nb
diff = calc
calc = 0.5 * (calc + nb / calc)
while calc != diff:
diff = calc
calc = 0.5 * (calc + nb / calc)
return calc
def exit_error(error):
print("{prog} - error: {err}".format(prog=sys.argv[0], err=error))
sys.exit(-1)