26#if ! defined (octave_oct_mappers_h)
27#define octave_oct_mappers_h 1
29#include "octave-config.h"
45 if constexpr (std::is_unsigned_v<T>)
48 return std::abs (
x.value ());
63inline double copysign (
double x,
double y) {
return std::copysign (
x, y); }
64inline float copysign (
float x,
float y) {
return std::copysignf (
x, y); }
66inline double signbit (
double x) {
return std::signbit (
x); }
67inline float signbit (
float x) {
return std::signbit (
x); }
88inline double conj (
double x) {
return x; }
89inline float conj (
float x) {
return x; }
98inline double log2 (
double x) {
return std::log2 (
x); }
99inline float log2 (
float x) {
return std::log2f (
x); }
110inline double exp2 (
double x) {
return std::exp2 (
x); }
111inline float exp2 (
float x) {
return std::exp2f (
x); }
117 return std::complex<T> (std::ceil (std::real (
x)),
118 std::ceil (std::imag (
x)));
125 return std::complex<T> (std::trunc (std::real (
x)),
126 std::trunc (std::imag (
x)));
130inline double fix (
double x) {
return std::trunc (
x); }
131inline float fix (
float x) {
return std::trunc (
x); }
144 return std::complex<T> (std::floor (std::real (
x)),
145 std::floor (std::imag (
x)));
148inline double round (
double x) {
return std::round (
x); }
149inline float round (
float x) {
return std::roundf (
x); }
155 return std::complex<T> (
round (std::real (
x)),
round (std::imag (
x)));
163 if (fabs (
x - t) == 0.5)
164 t = 2 * std::trunc (0.5 * t);
174 if (fabsf (
x - t) == 0.5f)
175 t = 2 * std::trunc (0.5f * t);
184 return std::complex<T> (
roundb (std::real (
x)),
roundb (std::imag (
x)));
192inline bool isnan (
bool) {
return false; }
193inline bool isnan (
char) {
return false; }
195inline bool isnan (
double x) {
return std::isnan (
x); }
196inline bool isnan (
float x) {
return std::isnan (
x); }
209 return (std::isnan (std::real (
x)) || std::isnan (std::imag (
x)));
212inline bool isinf (
double x) {
return std::isinf (
x); }
213inline bool isinf (
float x) {
return std::isinf (
x); }
226 return (std::isinf (std::real (
x)) || std::isinf (std::imag (
x)));
264 return isnan (
x) ? numeric_limits<double>::NaN () : tmp;
277 return isnan (
x) ? numeric_limits<float>::NaN () : tmp;
284 T tmp = std::abs (
x);
286 return tmp == 0 ? 0.0 :
x / tmp;
336 < std::numeric_limits<T>::epsilon ()))
340 T n = std::floor (q);
349 if (
x != y && y != 0)
362 retval = numeric_limits<T>::NaN ();
369 < std::numeric_limits<T>::epsilon ()))
373 T n = std::trunc (q);
382 if (
x != y && y != 0)
393 return x <= y ?
x : y;
400 return x >= y ?
x : y;
410 return x <= y ?
x : y;
416 return x >= y ?
x : y;
422 return isnan (y) ?
x : (
x <= y ?
x : y);
428 return isnan (y) ?
x : (
x >= y ?
x : y);
432min (
double x,
double y,
const bool nanflag)
438 out =
isnan (y) ?
x : (
x <= y ?
x : y);
443max (
double x,
double y,
const bool nanflag)
449 out =
isnan (y) ?
x : (
x >= y ?
x : y);
454min (
double x,
double y,
const bool nanflag,
const bool realabs)
460 out =
isnan (y) ?
x : (
x <= y ?
x : y);
463 (std::abs (
x) < std::abs (y) ?
x : (std::abs (
x) == std::abs (y) &&
x <= y ?
x : y));
468max (
double x,
double y,
const bool nanflag,
const bool realabs)
474 out =
isnan (y) ?
x : (
x >= y ?
x : y);
477 (std::abs (
x) > std::abs (y) ?
x : (std::abs (
x) == std::abs (y) &&
x >= y ?
x : y));
484 return isnan (y) ?
x : (
x <= y ?
x : y);
490 return isnan (y) ?
x : (
x >= y ?
x : y);
494min (
float x,
float y,
const bool nanflag)
500 out =
isnan (y) ?
x : (
x <= y ?
x : y);
505max (
float x,
float y,
const bool nanflag)
511 out =
isnan (y) ?
x : (
x >= y ?
x : y);
516min (
float x,
float y,
const bool nanflag,
const bool realabs)
522 out =
isnan (y) ?
x : (
x <= y ?
x : y);
525 (std::abs (
x) < std::abs (y) ?
x :
526 (std::abs (
x) == std::abs (y) &&
x <= y ?
x : y));
531max (
float x,
float y,
const bool nanflag,
const bool realabs)
537 out =
isnan (y) ?
x : (
x >= y ?
x : y);
540 (std::abs (
x) > std::abs (y) ?
x :
541 (std::abs (
x) == std::abs (y) &&
x >= y ?
x : y));
545inline std::complex<double>
546min (
const std::complex<double>&
x,
const std::complex<double>& y)
548 return isnan (y) ?
x : (std::abs (
x) < std::abs (y) ?
x :
549 (std::abs (
x) == std::abs (y) && std::arg (
x) <= std::arg (y) ?
x : y));
552inline std::complex<double>
553max (
const std::complex<double>&
x,
const std::complex<double>& y)
555 return isnan (y) ?
x : (std::abs (
x) > std::abs (y) ?
x :
556 (std::abs (
x) == std::abs (y) && std::arg (
x) >= std::arg (y) ?
x : y));
559inline std::complex<double>
560min (
const std::complex<double>&
x,
const std::complex<double>& y,
563 std::complex<double> out;
567 out =
isnan (y) ?
x : (std::abs (
x) < std::abs (y) ?
x :
568 (std::abs (
x) == std::abs (y) && std::arg (
x) <= std::arg (y) ?
x : y));
572inline std::complex<double>
573max (
const std::complex<double>&
x,
const std::complex<double>& y,
576 std::complex<double> out;
580 out =
isnan (y) ?
x : (std::abs (
x) > std::abs (y) ?
x :
581 (std::abs (
x) == std::abs (y) && std::arg (
x) >= std::arg (y) ?
x : y));
585inline std::complex<double>
586min (
const std::complex<double>&
x,
const std::complex<double>& y,
587 const bool nanflag,
const bool realabs)
589 std::complex<double> out;
593 out =
isnan (y) ?
x : (std::real (
x) < std::real (y) ?
x :
594 (std::real (
x) == std::real (y) &&
595 std::imag (
x) <= std::imag (y) ?
x : y));
597 out =
isnan (y) ?
x : (std::abs (
x) < std::abs (y) ?
x :
598 (std::abs (
x) == std::abs (y) && std::arg (
x) <= std::arg (y) ?
x : y));
602inline std::complex<double>
603max (
const std::complex<double>&
x,
const std::complex<double>& y,
604 const bool nanflag,
const bool realabs)
606 std::complex<double> out;
610 out =
isnan (y) ?
x : (std::real (
x) > std::real (y) ?
x :
611 (std::real (
x) == std::real (y) &&
612 std::imag (
x) >= std::imag (y) ?
x : y));
614 out =
isnan (y) ?
x : (std::abs (
x) > std::abs (y) ?
x :
615 (std::abs (
x) == std::abs (y) && std::arg (
x) >= std::arg (y) ?
x : y));
619inline std::complex<float>
620min (
const std::complex<float>&
x,
const std::complex<float>& y)
623 (std::abs (
x) == std::abs (y) && std::arg (
x) <= std::arg (y) ?
x : y));
626inline std::complex<float>
627max (
const std::complex<float>&
x,
const std::complex<float>& y)
630 (std::abs (
x) == std::abs (y) && std::arg (
x) >= std::arg (y) ?
x : y));
633inline std::complex<float>
634min (
const std::complex<float>&
x,
const std::complex<float>& y,
637 std::complex<float> out;
641 out =
isnan (y) ?
x : (std::abs (
x) < std::abs (y) ?
x :
642 (std::abs (
x) == std::abs (y) && std::arg (
x) <= std::arg (y) ?
x : y));
646inline std::complex<float>
647max (
const std::complex<float>&
x,
const std::complex<float>& y,
650 std::complex<float> out;
654 out =
isnan (y) ?
x : (std::abs (
x) > std::abs (y) ?
x :
655 (std::abs (
x) == std::abs (y) && std::arg (
x) >= std::arg (y) ?
x : y));
659inline std::complex<float>
660min (
const std::complex<float>&
x,
const std::complex<float>& y,
661 const bool nanflag,
const bool realabs)
663 std::complex<float> out;
667 out =
isnan (y) ?
x : (std::real (
x) < std::real (y) ?
x :
668 (std::real (
x) == std::real (y) &&
669 std::imag (
x) <= std::imag (y) ?
x : y));
671 out =
isnan (y) ?
x : (std::abs (
x) < std::abs (y) ?
x :
672 (std::abs (
x) == std::abs (y) && std::arg (
x) <= std::arg (y) ?
x : y));
676inline std::complex<float>
677max (
const std::complex<float>&
x,
const std::complex<float>& y,
678 const bool nanflag,
const bool realabs)
680 std::complex<float> out;
684 out =
isnan (y) ?
x : (std::real (
x) > std::real (y) ?
x :
685 (std::real (
x) == std::real (y) &&
686 std::imag (
x) >= std::imag (y) ?
x : y));
688 out =
isnan (y) ?
x : (std::abs (
x) > std::abs (y) ?
x :
689 (std::abs (
x) == std::abs (y) && std::arg (
x) >= std::arg (y) ?
x : y));
710 [[maybe_unused]]
const bool nanflag)
718 [[maybe_unused]]
const bool nanflag)
726 [[maybe_unused]]
const bool nanflag,
const bool realabs)
734 x.value () <= y.
value () ?
x : y);
741 [[maybe_unused]]
const bool nanflag,
const bool realabs)
749 x.value () >= y.
value () ?
x : y);
779OCTAVE_END_NAMESPACE(math)
780OCTAVE_END_NAMESPACE(octave)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::complex< T > ceil(const std::complex< T > &x)
Complex atan(const Complex &x)
bool is_NaN_or_NA(const Complex &x)
std::complex< T > floor(const std::complex< T > &x)
Complex asin(const Complex &x)
bool positive_sign(double x)
octave_idx_type nint_big(double x)
bool negative_sign(double x)
auto mappers_abs(const octave_int< T > &x)
double copysign(double x, double y)
Complex acos(const Complex &x)
std::complex< T > trunc(const std::complex< T > &x)
bool is_integer(double x)
double frexp(double x, int *expptr)
OCTAVE_DEPRECATED(11, "") typedef bool(*b_d_Mapper)(double)
std::complex< double > Complex
std::complex< float > FloatComplex
template int8_t abs(int8_t)
F77_RET_T const F77_DBLE * x