3838
3939// Provides some commonly repeated, basic loop templates.
4040
41- template <typename T>
42- inline auto mappers_abs (const T& x)
43- {
44- if constexpr (std::is_unsigned_v<T>)
45- return x; // abs doesn't make sense for unsigned types
46- else
47- return std::abs (x);
48- }
4941// Specialization for octave_int types
5042template <typename T>
5143inline auto mappers_abs (const octave_int<T>& x)
5244{
5345 if constexpr (std::is_unsigned_v<T>)
5446 return x; // abs doesn't make sense for unsigned types
5547 else
56- return abs (x.value ());
48+ return std:: abs (x.value ());
5749}
5850
5951
@@ -283,7 +275,7 @@ template <typename T>
283275std::complex <T>
284276signum (const std::complex <T>& x)
285277{
286- T tmp = mappers_abs (x);
278+ T tmp = std::abs (x);
287279
288280 return tmp == 0 ? 0.0 : x / tmp;
289281}
@@ -524,7 +516,8 @@ min (float x, float y, const bool nanflag, const bool realabs)
524516 out = isnan (y) ? x : (x <= y ? x : y);
525517 else
526518 out = isnan (y) ? x :
527- (std::abs (x) < std::abs (y) ? x : (std::abs (x) == std::abs (y) && x <= y ? x : y));
519+ (std::abs (x) < std::abs (y) ? x :
520+ (std::abs (x) == std::abs (y) && x <= y ? x : y));
528521 return out;
529522}
530523
@@ -538,22 +531,23 @@ max (float x, float y, const bool nanflag, const bool realabs)
538531 out = isnan (y) ? x : (x >= y ? x : y);
539532 else
540533 out = isnan (y) ? x :
541- (std::abs (x) > std::abs (y) ? x : (std::abs (x) == std::abs (y) && x >= y ? x : y));
534+ (std::abs (x) > std::abs (y) ? x :
535+ (std::abs (x) == std::abs (y) && x >= y ? x : y));
542536 return out;
543537}
544538
545539inline std::complex <double >
546540min (const std::complex <double >& x, const std::complex <double >& y)
547541{
548- return isnan (y) ? x : (mappers_abs (x) < mappers_abs (y) ? x :
549- (mappers_abs (x) == mappers_abs (y) && std::arg (x) <= std::arg (y) ? x : y));
542+ return isnan (y) ? x : (std::abs (x) < std::abs (y) ? x :
543+ (std::abs (x) == std::abs (y) && std::arg (x) <= std::arg (y) ? x : y));
550544}
551545
552546inline std::complex <double >
553547max (const std::complex <double >& x, const std::complex <double >& y)
554548{
555- return isnan (y) ? x : (mappers_abs (x) > mappers_abs (y) ? x :
556- (mappers_abs (x) == mappers_abs (y) && std::arg (x) >= std::arg (y) ? x : y));
549+ return isnan (y) ? x : (std::abs (x) > std::abs (y) ? x :
550+ (std::abs (x) == std::abs (y) && std::arg (x) >= std::arg (y) ? x : y));
557551}
558552
559553inline std::complex <double >
@@ -564,8 +558,8 @@ min (const std::complex<double>& x, const std::complex<double>& y,
564558 if (! nanflag && (isnan (x) || isnan (y)))
565559 out = NAN;
566560 else
567- out = isnan (y) ? x : (mappers_abs (x) < mappers_abs (y) ? x :
568- (mappers_abs (x) == mappers_abs (y) && std::arg (x) <= std::arg (y) ? x : y));
561+ out = isnan (y) ? x : (std::abs (x) < std::abs (y) ? x :
562+ (std::abs (x) == std::abs (y) && std::arg (x) <= std::arg (y) ? x : y));
569563 return out;
570564}
571565
@@ -577,8 +571,8 @@ max (const std::complex<double>& x, const std::complex<double>& y,
577571 if (! nanflag && (isnan (x) || isnan (y)))
578572 out = NAN;
579573 else
580- out = isnan (y) ? x : (mappers_abs (x) > mappers_abs (y) ? x :
581- (mappers_abs (x) == mappers_abs (y) && std::arg (x) >= std::arg (y) ? x : y));
574+ out = isnan (y) ? x : (std::abs (x) > std::abs (y) ? x :
575+ (std::abs (x) == std::abs (y) && std::arg (x) >= std::arg (y) ? x : y));
582576 return out;
583577}
584578
@@ -594,8 +588,8 @@ min (const std::complex<double>& x, const std::complex<double>& y,
594588 (std::real (x) == std::real (y) &&
595589 std::imag (x) <= std::imag (y) ? x : y));
596590 else
597- out = isnan (y) ? x : (mappers_abs (x) < mappers_abs (y) ? x :
598- (mappers_abs (x) == mappers_abs (y) && std::arg (x) <= std::arg (y) ? x : y));
591+ out = isnan (y) ? x : (std::abs (x) < std::abs (y) ? x :
592+ (std::abs (x) == std::abs (y) && std::arg (x) <= std::arg (y) ? x : y));
599593 return out;
600594}
601595
@@ -611,23 +605,23 @@ max (const std::complex<double>& x, const std::complex<double>& y,
611605 (std::real (x) == std::real (y) &&
612606 std::imag (x) >= std::imag (y) ? x : y));
613607 else
614- out = isnan (y) ? x : (mappers_abs (x) > mappers_abs (y) ? x :
615- (mappers_abs (x) == mappers_abs (y) && std::arg (x) >= std::arg (y) ? x : y));
608+ out = isnan (y) ? x : (std::abs (x) > std::abs (y) ? x :
609+ (std::abs (x) == std::abs (y) && std::arg (x) >= std::arg (y) ? x : y));
616610 return out;
617611}
618612
619613inline std::complex <float >
620614min (const std::complex <float >& x, const std::complex <float >& y)
621615{
622616 return isnan (y) ? x : (abs (x) < abs (y) ? x :
623- (mappers_abs (x) == mappers_abs (y) && std::arg (x) <= std::arg (y) ? x : y));
617+ (std::abs (x) == std::abs (y) && std::arg (x) <= std::arg (y) ? x : y));
624618}
625619
626620inline std::complex <float >
627621max (const std::complex <float >& x, const std::complex <float >& y)
628622{
629623 return isnan (y) ? x : (abs (x) > abs (y) ? x :
630- (mappers_abs (x) == mappers_abs (y) && std::arg (x) >= std::arg (y) ? x : y));
624+ (std::abs (x) == std::abs (y) && std::arg (x) >= std::arg (y) ? x : y));
631625}
632626
633627inline std::complex <float >
@@ -638,8 +632,8 @@ min (const std::complex<float>& x, const std::complex<float>& y,
638632 if (! nanflag && (isnan (x) || isnan (y)))
639633 out = NAN;
640634 else
641- out = isnan (y) ? x : (mappers_abs (x) < mappers_abs (y) ? x :
642- (mappers_abs (x) == mappers_abs (y) && std::arg (x) <= std::arg (y) ? x : y));
635+ out = isnan (y) ? x : (std::abs (x) < std::abs (y) ? x :
636+ (std::abs (x) == std::abs (y) && std::arg (x) <= std::arg (y) ? x : y));
643637 return out;
644638}
645639
@@ -651,8 +645,8 @@ max (const std::complex<float>& x, const std::complex<float>& y,
651645 if (! nanflag && (isnan (x) || isnan (y)))
652646 out = NAN;
653647 else
654- out = isnan (y) ? x : (mappers_abs (x) > mappers_abs (y) ? x :
655- (mappers_abs (x) == mappers_abs (y) && std::arg (x) >= std::arg (y) ? x : y));
648+ out = isnan (y) ? x : (std::abs (x) > std::abs (y) ? x :
649+ (std::abs (x) == std::abs (y) && std::arg (x) >= std::arg (y) ? x : y));
656650 return out;
657651}
658652
@@ -668,8 +662,8 @@ min (const std::complex<float>& x, const std::complex<float>& y,
668662 (std::real (x) == std::real (y) &&
669663 std::imag (x) <= std::imag (y) ? x : y));
670664 else
671- out = isnan (y) ? x : (mappers_abs (x) < mappers_abs (y) ? x :
672- (mappers_abs (x) == mappers_abs (y) && std::arg (x) <= std::arg (y) ? x : y));
665+ out = isnan (y) ? x : (std::abs (x) < std::abs (y) ? x :
666+ (std::abs (x) == std::abs (y) && std::arg (x) <= std::arg (y) ? x : y));
673667 return out;
674668}
675669
@@ -685,8 +679,8 @@ max (const std::complex<float>& x, const std::complex<float>& y,
685679 (std::real (x) == std::real (y) &&
686680 std::imag (x) >= std::imag (y) ? x : y));
687681 else
688- out = isnan (y) ? x : (mappers_abs (x) > mappers_abs (y) ? x :
689- (mappers_abs (x) == mappers_abs (y) && std::arg (x) >= std::arg (y) ? x : y));
682+ out = isnan (y) ? x : (std::abs (x) > std::abs (y) ? x :
683+ (std::abs (x) == std::abs (y) && std::arg (x) >= std::arg (y) ? x : y));
690684 return out;
691685}
692686
@@ -729,8 +723,8 @@ min (const octave_int<T>& x, const octave_int<T>& y,
729723 if (realabs)
730724 out = x.value () <= y.value () ? x : y;
731725 else
732- out = mappers_abs (x. value ()) < mappers_abs (y. value () ) ? x :
733- (mappers_abs (x. value ()) == mappers_abs (y. value () ) &&
726+ out = mappers_abs (x) < mappers_abs (y) ? x :
727+ (mappers_abs (x) == mappers_abs (y) &&
734728 x.value () <= y.value () ? x : y);
735729 return out;
736730}
@@ -744,8 +738,8 @@ max (const octave_int<T>& x, const octave_int<T>& y,
744738 if (realabs)
745739 out = x.value () >= y.value () ? x : y;
746740 else
747- out = mappers_abs (x. value ()) > mappers_abs (y. value () ) ? x :
748- (mappers_abs (x. value ()) == mappers_abs (y. value () ) &&
741+ out = mappers_abs (x) > mappers_abs (y) ? x :
742+ (mappers_abs (x) == mappers_abs (y) &&
749743 x.value () >= y.value () ? x : y);
750744 return out;
751745}
0 commit comments