Skip to content

Commit ddbcc44

Browse files
committed
Use std::div()
1 parent f23aa08 commit ddbcc44

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

jsrc/conversions.cpp

+7-6
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" {
@@ -142,9 +143,10 @@ convert<int64_t, X>(J jt, array w, void *yv) -> bool {
142143
auto 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, XBASE);
147+
u[i] = r;
148+
d = q;
149+
if (r) length = i;
148150
}
149151
++length;
150152
*u += b;
@@ -176,9 +178,8 @@ jtxd1(J jt, double p, int64_t mode) -> X {
176178
int64_t m = 0;
177179
auto 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, 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)