@@ -258,34 +258,35 @@ convert<X, Q>(J jt, A w, void *yv) -> bool {
258258template <>
259259[[nodiscard]] auto
260260convert<D, Q>(J jt, A w, void *yv, I mode) -> bool {
261- B neg, recip;
262- D c, d, t, *wv;
263- I e, i, n, *v;
264- Q q, *x;
265- S *tv;
266261 if (!(w)) return 0 ;
267- n = AN (w);
268- wv = DAV (w);
269- x = (Q *)yv;
270- tv = 3 + (S *)&t;
271- for (i = 0 ; i < n; ++i) {
262+ auto const n = AN (w);
263+ auto const wv = DAV (w);
264+ auto x = (Q *)yv;
265+ D t;
266+ auto tv = 3 + (S *)&t;
267+ Q q;
268+ for (int64_t i = 0 ; i < n; ++i) {
272269 t = wv[i];
273270 ASSERT (!_isnan (t), EVNAN);
274- if ((neg = 0 > t)) t = -t;
271+ bool const neg = 0 > t;
272+ if (neg) t = -t;
275273 q.d = iv1;
276274 if (t == inf)
277275 q.n = jtvci (jt, XPINF);
278276 else if (t == 0.0 )
279277 q.n = iv0;
280278 else if (1.1102230246251565e-16 < t && t < 9.007199254740992e15 ) {
281- d = jround (1 / jtdgcd (jt, 1.0 , t));
282- c = jround (d * t);
283- q.n = jtxd1 (jt, c, mode);
284- q.d = jtxd1 (jt, d, mode);
285- q = jtqstd (jt, q);
279+ auto const d = jround (1 / jtdgcd (jt, 1.0 , t));
280+ auto const c = jround (d * t);
281+ q = jtqstd (jt,
282+ {
283+ .n = jtxd1 (jt, c, mode),
284+ .d = jtxd1 (jt, d, mode),
285+ });
286286 } else {
287- if ((recip = 1 > t)) t = 1.0 / t;
288- e = (I)(0xfff0 & *tv);
287+ bool const recip = 1 > t;
288+ if (recip) t = 1.0 / t;
289+ auto e = (I)(0xfff0 & *tv);
289290 e >>= 4 ;
290291 e -= 1023 ;
291292 if (recip) {
@@ -297,7 +298,7 @@ convert<D, Q>(J jt, A w, void *yv, I mode) -> bool {
297298 }
298299 }
299300 if (neg) {
300- v = AV (q.n );
301+ auto v = AV (q.n );
301302 DQ (AN (q.n ), *v = -*v; ++v;);
302303 }
303304 *x++ = q;
@@ -381,13 +382,10 @@ convert<D, Z>(J jt, A w, void *yv) -> bool {
381382B
382383jtccvt (J jt, I tflagged, A w, A *y) {
383384 FPREFIP;
384- A d;
385- I n, r, *s, wt;
386- void *wv, *yv;
387- I t = tflagged & NOUN;
385+ I const t = tflagged & NOUN;
388386 if (!w) return 0 ;
389- r = AR (w);
390- s = AS (w);
387+ auto const r = AR (w);
388+ auto const s = AS (w);
391389 if (((t | AT (w)) & SPARSE) != 0 ) {
392390 // Handle sparse
393391 RANK2T oqr = jt->ranks ;
@@ -415,8 +413,7 @@ jtccvt(J jt, I tflagged, A w, A *y) {
415413 jt->ranks = oqr;
416414 }
417415 // Now known to be non-sparse
418- n = AN (w);
419- wt = AT (w);
416+ auto const wt = AT (w);
420417 // If type is already correct, return a clone - used to force a copy. Should get rid of this kludge
421418 if (TYPESEQ (t, wt)) {
422419 RZ (*y = jtca (jt, w));
@@ -427,13 +424,15 @@ jtccvt(J jt, I tflagged, A w, A *y) {
427424 // replace n (for use here) and yv, and AK(w) and AN(w) for the subroutines. If NOUNCVTVALIDCT is set, w is
428425 // modified: the caller must restore AN(w) and AK(w) if it needs it
429426 // TODO: same-length conversion could be done in place
427+ auto n = AN (w);
428+ A d;
430429 GA (d, t, n, r, s);
431- yv = voidAV (d); // allocate the same # atoms, even if we will convert fewer
430+ auto yv = voidAV (d); // allocate the same # atoms, even if we will convert fewer
432431 if (tflagged & NOUNCVTVALIDCT) {
433- I inputn = *(I *)y; // fetch input, in case it is called for
434- if (inputn > 0 ) { // if converting the leading values, just update the counts
435- n = inputn; // set the counts for local use, and in the block to be converted
436- } else { // if converting trailing values...
432+ I inputn = *(I *)y; // fetch input, in case it is called for
433+ if (inputn > 0 ) { // if converting the leading values, just update the counts
434+ n = inputn; // set the counts for local use, and in the block to be converted
435+ } else { // if converting trailing values...
437436 AK (w) += (n + inputn) << bplg (wt);
438437 yv = (I *)((C *)yv + ((n + inputn) << bplg (t))); // advance input and output pointers to new area
439438 n = -inputn; // get positive # atoms to convert
@@ -443,8 +442,8 @@ jtccvt(J jt, I tflagged, A w, A *y) {
443442 // If n and AN have been modified, it doesn't matter for rank-1 arguments whether the shape of the result is listed
444443 // as n or s[0] since only n atoms will be used. For higher ranks, we need the shape from s. So it's just as well
445444 // that we take the shape from s now
446- *y = d;
447- wv = voidAV (w); // return the address of the new block
445+ *y = d;
446+ auto wv = voidAV (w); // return the address of the new block
448447 if (t & CMPX) jtfillv (jt, t, n, (C *)yv); // why?? just fill in imaginary parts as we need to
449448 if (!n) return 1 ;
450449 // Perform the conversion based on data types
@@ -466,14 +465,12 @@ jtccvt(J jt, I tflagged, A w, A *y) {
466465 }
467466 }
468467 switch (CVCASE (CTTZ (t), CTTZ (wt))) {
469- case CVCASE (INTX, B01X):
470- std::copy_n (static_cast <B*>(wv), n, static_cast <I*>(yv));
471- return 1 ;
468+ case CVCASE (INTX, B01X): std::copy_n (static_cast <B *>(wv), n, static_cast <I *>(yv)); return 1 ;
472469 case CVCASE (XNUMX, B01X): return convert<bool , X>(jt, w, yv);
473- case CVCASE (RATX, B01X): GATV (d, XNUM, n, r, s); return convert< bool , X>(jt, w, AV (d)) && convert<X, Q>(jt, d, yv);
474- case CVCASE (FLX, B01X):
475- std::copy_n ( static_cast <B*>(wv), n, static_cast <D*>(yv) );
476- return 1 ;
470+ case CVCASE (RATX, B01X):
471+ GATV (d, XNUM, n, r, s);
472+ return convert< bool , X>(jt, w, AV (d)) && convert<X, Q>(jt, d, yv );
473+ case CVCASE (FLX, B01X): std::copy_n ( static_cast <B *>(wv), n, static_cast <D *>(yv)); return 1 ;
477474 case CVCASE (CMPXX, B01X): {
478475 Z *x = (Z *)yv;
479476 B *v = (B *)wv;
@@ -483,21 +480,21 @@ jtccvt(J jt, I tflagged, A w, A *y) {
483480 case CVCASE (B01X, INTX): return convert<I, bool >(jt, w, yv);
484481 case CVCASE (XNUMX, INTX): return convert<I, X>(jt, w, yv);
485482 case CVCASE (RATX, INTX): GATV (d, XNUM, n, r, s); return convert<I, X>(jt, w, AV (d)) && convert<X, Q>(jt, d, yv);
486- case CVCASE (FLX, INTX):
487- std::copy_n (static_cast <I*>(wv), n, static_cast <D*>(yv));
488- return 1 ;
483+ case CVCASE (FLX, INTX): std::copy_n (static_cast <I *>(wv), n, static_cast <D *>(yv)); return 1 ;
489484 case CVCASE (CMPXX, INTX): {
490485 Z *x = (Z *)yv;
491- I *v = static_cast <I*>(wv);
486+ I *v = static_cast <I *>(wv);
492487 DQ (n, x++->re = (D)*v++;);
493488 }
494489 return 1 ;
495490 case CVCASE (B01X, FLX): return convert<D, bool >(jt, w, yv, (I)jtinplace & JTNOFUZZ ? 0.0 : FUZZ);
496491 case CVCASE (INTX, FLX): return convert<D, I>(jt, w, yv, (I)jtinplace & JTNOFUZZ ? 0.0 : FUZZ);
497492 case CVCASE (XNUMX, FLX):
498- return convert<D, X>(jt, w, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
493+ return convert<D, X>(
494+ jt, w, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
499495 case CVCASE (RATX, FLX):
500- return convert<D, Q>(jt, w, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
496+ return convert<D, Q>(
497+ jt, w, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
501498 case CVCASE (CMPXX, FLX): return convert<D, Z>(jt, w, yv);
502499 case CVCASE (B01X, CMPXX):
503500 GATV (d, FL, n, r, s);
@@ -510,11 +507,13 @@ jtccvt(J jt, I tflagged, A w, A *y) {
510507 case CVCASE (XNUMX, CMPXX):
511508 GATV (d, FL, n, r, s);
512509 if (!(convert<Z, D>(jt, w, AV (d), (I)jtinplace & JTNOFUZZ ? 0.0 : FUZZ))) return 0 ;
513- return convert<D, X>(jt, d, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
510+ return convert<D, X>(
511+ jt, d, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
514512 case CVCASE (RATX, CMPXX):
515513 GATV (d, FL, n, r, s);
516514 if (!(convert<Z, D>(jt, w, AV (d), (I)jtinplace & JTNOFUZZ ? 0.0 : FUZZ))) return 0 ;
517- return convert<D, Q>(jt, d, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
515+ return convert<D, Q>(
516+ jt, d, yv, (jt->xmode & REPSGN (SGNIFNOT (tflagged, XCVTXNUMORIDEX))) | (tflagged >> XCVTXNUMCVX));
518517 case CVCASE (FLX, CMPXX): return convert<Z, D>(jt, w, yv, (I)jtinplace & JTNOFUZZ ? 0.0 : FUZZ);
519518 case CVCASE (B01X, XNUMX): return convert<X, bool >(jt, w, yv);
520519 case CVCASE (INTX, XNUMX): return convert<X, I>(jt, w, yv);
@@ -604,15 +603,13 @@ jtbcvt(J jt, C mode, A w) {
604603
605604A
606605jticvt (J jt, A w) {
606+ auto const n = AN (w);
607+ auto const * v = DAV (w);
607608 A z;
608- D *v, x;
609- I i, n, *u;
610- n = AN (w);
611- v = DAV (w);
612609 GATV (z, INT, n, AR (w), AS (w));
613- u = AV (z);
614- for (i = 0 ; i < n; ++i) {
615- x = *v++;
610+ auto u = AV (z);
611+ for (int64_t i = 0 ; i < n; ++i) {
612+ auto x = *v++;
616613 if (x < IMIN || FLIMAX <= x) return w; // if conversion will fail, skip it
617614 *u++ = (I)x;
618615 }
@@ -621,12 +618,11 @@ jticvt(J jt, A w) {
621618
622619A
623620jtpcvt (J jt, I t, A w) {
624- A y;
625- B b;
626621 RANK2T oqr = jt->ranks ;
627622 RESETRANK;
628- b = jtccvt (jt, t, w, &y);
629- jt->ranks = oqr;
623+ A y;
624+ bool const b = jtccvt (jt, t, w, &y);
625+ jt->ranks = oqr;
630626 return b ? y : w;
631627} /* convert w to type t, if possible, otherwise just return w */
632628
0 commit comments