blob: 708d759f6d5b67fe72eea661898b3e0e64fa90d6 (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# author : S. Mandalia
# shivesh.mandalia@outlook.com
#
# date : March 19, 2020
"""
Miscellaneous utility methods.
"""
__all__ = ['is_num', 'is_pos']
def is_num(val: (int, float)) -> bool:
"""
Check if the input value is a non-infinite number.
Parameters
----------
val : Value to check.
Returns
----------
is_num : Whether it is a non-infinite number.
Examples
----------
>>> from utils.misc import is_num
>>> print(is_num(10))
True
>>> print(is_num(None))
False
"""
if not isinstance(val, (int, float)):
return False
return True
def is_pos(val: (int, float)) -> bool:
"""
Check if the input value is a non-infinite positive number.
Parameters
----------
val : Value to check.
Returns
----------
is_pos : Whether it is a non-infinite positive number.
Examples
----------
>>> from utils.misc import is_pos
>>> print(is_pos(10))
True
>>> print(is_pos(-10))
False
"""
if not is_num(val):
return False
if not val >= 0:
return False
return True
|