MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / abs_val

Function abs_val

maths/abs.py:4–15  ·  view source on GitHub ↗

Find the absolute value of a number. >>> abs_val(-5.1) 5.1 >>> abs_val(-5) == abs_val(5) True >>> abs_val(0) 0

(num: float)

Source from the content-addressed store, hash-verified

2
3
4def abs_val(num: float) -> float:
5 """
6 Find the absolute value of a number.
7
8 >>> abs_val(-5.1)
9 5.1
10 >>> abs_val(-5) == abs_val(5)
11 True
12 >>> abs_val(0)
13 0
14 """
15 return -num if num < 0 else num
16
17
18def abs_min(x: list[int]) -> int:

Callers 3

abs_minFunction · 0.85
test_abs_valFunction · 0.85
abs.pyFile · 0.85

Calls

no outgoing calls

Tested by 1

test_abs_valFunction · 0.68