math ¶
Functions:
-
clamp–Faster max(min(value, max_val), min_val) "wrapper"
-
clamp_arr–Map an array to clamp.
-
cround–Rounding function that accounts for float's imprecision.
-
mod2–Force a value to be mod 2
-
mod4–Force a value to be mod 4
-
mod8–Force a value to be mod 8
-
mod_x–Force a value to be divisible by x (val % x == 0).
-
ndigits– -
next_power_of_2–Get the next power of 2 of x.
-
next_power_of_y–Get the next power of y of x.
-
spline_coeff–Get spline coefficient of an index and coordinates.
clamp ¶
clamp(val: Nb, min_val: Nb, max_val: Nb) -> Nb
Faster max(min(value, max_val), min_val) "wrapper"
Source code in jetpytools/utils/math.py
20 21 22 23 | |
clamp_arr ¶
Map an array to clamp.
Source code in jetpytools/utils/math.py
26 27 28 29 | |
cround ¶
Rounding function that accounts for float's imprecision.
Source code in jetpytools/utils/math.py
32 33 34 35 | |
mod2 ¶
Force a value to be mod 2
Source code in jetpytools/utils/math.py
47 48 49 50 | |
mod4 ¶
Force a value to be mod 4
Source code in jetpytools/utils/math.py
53 54 55 56 | |
mod8 ¶
Force a value to be mod 8
Source code in jetpytools/utils/math.py
59 60 61 62 | |
mod_x ¶
Force a value to be divisible by x (val % x == 0).
Source code in jetpytools/utils/math.py
38 39 40 41 42 43 44 | |
ndigits ¶
Source code in jetpytools/utils/math.py
164 165 166 167 168 169 | |
next_power_of_2 ¶
Get the next power of 2 of x.
Source code in jetpytools/utils/math.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
next_power_of_y ¶
Get the next power of y of x.
Source code in jetpytools/utils/math.py
82 83 84 85 86 87 88 89 | |
spline_coeff ¶
spline_coeff(
x: int,
coordinates: list[tuple[float, float]] = [
(0, 0),
(0.5, 0.1),
(1, 0.6),
(2, 0.9),
(2.5, 1),
(3, 1.1),
(3.5, 1.15),
(4, 1.2),
(8, 1.25),
(255, 1.5),
],
) -> float
Get spline coefficient of an index and coordinates.
Source code in jetpytools/utils/math.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |