Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e30b14c

Browse filesBrowse files
Change Floor_div fun
1 parent 0466a52 commit e30b14c
Copy full SHA for e30b14c

File tree

1 file changed

+14
-14
lines changed
Filter options

1 file changed

+14
-14
lines changed

‎numpy/_core/src/umath/loops_arithmetic.dispatch.cpp

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/loops_arithmetic.dispatch.cpp
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,23 @@ void simd_divide_by_scalar_contig_unsigned(T* src, T scalar, T* dst, npy_intp le
137137
}
138138

139139

140-
// Floor division for signed integers
140+
// Helper function for floor division
141141
template <typename T>
142-
T floor_div(T n, T d) {
143-
if (HWY_UNLIKELY(d == 0 || (n == std::numeric_limits<T>::min() && d == -1))) {
144-
if (d == 0) {
145-
npy_set_floatstatus_divbyzero();
146-
return 0;
147-
} else {
148-
npy_set_floatstatus_overflow();
149-
return std::numeric_limits<T>::min();
150-
}
142+
T floor_div(T a, T b) {
143+
if (HWY_UNLIKELY(b == 0)) {
144+
npy_set_floatstatus_divbyzero();
145+
return 0;
146+
}
147+
if (HWY_UNLIKELY(std::is_signed<T>::value && a == std::numeric_limits<T>::min() && b == -1)) {
148+
npy_set_floatstatus_overflow();
149+
return std::numeric_limits<T>::min();
151150
}
152-
T r = n / d;
153-
if (((n > 0) != (d > 0)) && ((r * d) != n)) {
154-
r--;
151+
T q = a / b;
152+
T r = a % b;
153+
if ((r != 0) && ((a < 0) != (b < 0))) {
154+
q -= 1;
155155
}
156-
return r;
156+
return q;
157157
}
158158

159159
// Dispatch functions for signed integer division

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.