Skip to content

Commit 86ae356

Browse files
committed
Use std::div()
1 parent 2110d69 commit 86ae356

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

jsrc/conversions.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <limits>
88
#include <numeric>
99
#include <optional>
10+
#include <cstdlib>
1011

1112
#include "array.hpp"
1213
extern "C" {
@@ -138,13 +139,14 @@ template <>
138139
convert<int64_t, X>(J jt, array w, void *yv) -> bool {
139140
int64_t u[XIDIG];
140141
auto const convert_one = [&](auto c) {
141-
auto const b = c == IMIN;
142-
auto d = b ? -(1 + c) : std::abs(c);
142+
bool const b = c == IMIN;
143+
int64_t d = b ? -(1 + c) : std::abs(c);
143144
int64_t length = 0;
144145
for (int64_t i = 0; i < XIDIG; ++i) {
145-
u[i] = d % XBASE;
146-
d = d / XBASE;
147-
if (u[i]) length = i;
146+
auto const [q, r] = std::div(d, int64_t{XBASE});
147+
u[i] = r;
148+
d = q;
149+
if (r) length = i;
148150
}
149151
++length;
150152
*u += b;
@@ -174,11 +176,10 @@ jtxd1(J jt, double p, int64_t mode) -> X {
174176
if (!t) return 0;
175177
auto *u = pointer_to_values<int64_t>(t);
176178
int64_t m = 0;
177-
auto d = std::abs(p);
179+
int64_t d = std::abs(p);
178180
while (0 < d) {
179-
auto const q = floor(d / XBASE);
180-
auto const r = d - q * XBASE;
181-
u[m++] = static_cast<int64_t>(r);
181+
auto const [q, r] = std::div(d, int64_t{XBASE});
182+
u[m++] = r;
182183
d = q;
183184
if (m == AN(t)) {
184185
RZ(t = jtext(jt, 0, t));

0 commit comments

Comments
 (0)