@@ -896,7 +896,9 @@ namespace xsimd
896896 batch_type k = reducer_t::reduce (self, x);
897897 x = reducer_t::approx (x);
898898 x = select (self <= reducer_t::minlog (), batch_type (0 .), ldexp (x, to_int (k)));
899+ #ifndef __FAST_MATH__
899900 x = select (self >= reducer_t::maxlog (), constants::infinity<batch_type>(), x);
901+ #endif
900902 return x;
901903 }
902904
@@ -910,7 +912,9 @@ namespace xsimd
910912 batch_type c = reducer_t::approx (x);
911913 c = reducer_t::finalize (x, c, hi, lo);
912914 c = select (self <= reducer_t::minlog (), batch_type (0 .), ldexp (c, to_int (k)));
915+ #ifndef __FAST_MATH__
913916 c = select (self >= reducer_t::maxlog (), constants::infinity<batch_type>(), c);
917+ #endif
914918 return c;
915919 }
916920 }
@@ -1014,11 +1018,11 @@ namespace xsimd
10141018 XSIMD_INLINE batch<T, A> expm1 (batch<T, A> const & self, requires_arch<common>) noexcept
10151019 {
10161020 using batch_type = batch<T, A>;
1017- return select (self < constants::logeps<batch_type>(),
1018- batch_type (- 1 .),
1019- select (self > constants::maxlog<batch_type>(),
1020- constants::infinity<batch_type>(),
1021- detail::expm1 (self)) );
1021+ auto x = detail::expm1 (self);
1022+ # ifndef __FAST_MATH__
1023+ x = select (self > constants::maxlog<batch_type>(), constants::infinity<batch_type>(), x);
1024+ # endif
1025+ return select (self < constants::logeps<batch_type>(), batch_type (- 1 .), x );
10221026 }
10231027
10241028 template <class A , class T >
@@ -1245,12 +1249,20 @@ namespace xsimd
12451249 batch_type r1 = other (q);
12461250 if (any (ltza))
12471251 {
1252+ #ifdef __FAST_MATH__
1253+ r = negative (q, r1);
1254+ #else
12481255 r = select (inf_result, constants::infinity<batch_type>(), negative (q, r1));
1256+ #endif
12491257 if (all (ltza))
12501258 return r;
12511259 }
12521260 batch_type r2 = select (ltza, r, r1);
1261+ #ifdef __FAST_MATH__
1262+ return r2;
1263+ #else
12531264 return select (a == constants::minusinfinity<batch_type>(), constants::nan<batch_type>(), select (inf_result, constants::infinity<batch_type>(), r2));
1265+ #endif
12541266 }
12551267
12561268 private:
@@ -1371,7 +1383,11 @@ namespace xsimd
13711383 }
13721384 batch_type r1 = other (a);
13731385 batch_type r2 = select (test, r, r1);
1386+ #ifdef __FAST_MATH__
1387+ return r2;
1388+ #else
13741389 return select (a == constants::minusinfinity<batch_type>(), constants::nan<batch_type>(), select (inf_result, constants::infinity<batch_type>(), r2));
1390+ #endif
13751391 }
13761392
13771393 private:
@@ -1479,12 +1495,12 @@ namespace xsimd
14791495 batch_type hfsq = batch_type (0.5 ) * f * f;
14801496 batch_type dk = to_float (k);
14811497 batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, (hfsq + R), dk * constants::log_2lo<batch_type>()) - hfsq + f);
1482- #ifndef XSIMD_NO_INFINITIES
1483- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1498+ #ifdef __FAST_MATH__
1499+ return r ;
14841500#else
1485- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1486- #endif
1501+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
14871502 return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1503+ #endif
14881504 }
14891505
14901506 template <class A >
@@ -1522,12 +1538,12 @@ namespace xsimd
15221538 batch_type t2 = z * detail::horner<batch_type, 0x3fe5555555555593ll , 0x3fd2492494229359ll , 0x3fc7466496cb03dell , 0x3fc2f112df3e5244ll >(w);
15231539 batch_type R = t2 + t1;
15241540 batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, (hfsq + R), dk * constants::log_2lo<batch_type>()) - hfsq + f);
1525- #ifndef XSIMD_NO_INFINITIES
1526- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1541+ #ifdef __FAST_MATH__
1542+ return r ;
15271543#else
1528- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1529- #endif
1544+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
15301545 return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1546+ #endif
15311547 }
15321548
15331549 template <class A , class T >
@@ -1569,12 +1585,12 @@ namespace xsimd
15691585 batch_type hfsq = batch_type (0.5 ) * f * f;
15701586 batch_type dk = to_float (k);
15711587 batch_type r = fma (fms (s, hfsq + R, hfsq) + f, constants::invlog_2<batch_type>(), dk);
1572- #ifndef XSIMD_NO_INFINITIES
1573- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1588+ #ifdef __FAST_MATH__
1589+ return r ;
15741590#else
1575- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1576- #endif
1591+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
15771592 return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1593+ #endif
15781594 }
15791595
15801596 template <class A >
@@ -1617,12 +1633,12 @@ namespace xsimd
16171633 val_lo += (dk - w1) + val_hi;
16181634 val_hi = w1;
16191635 batch_type r = val_lo + val_hi;
1620- #ifndef XSIMD_NO_INFINITIES
1621- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1636+ #ifdef __FAST_MATH__
1637+ return r ;
16221638#else
1623- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1624- #endif
1639+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
16251640 return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1641+ #endif
16261642 }
16271643
16281644 namespace detail
@@ -1757,12 +1773,12 @@ namespace xsimd
17571773 val_lo += (y - w1) + val_hi;
17581774 val_hi = w1;
17591775 batch_type r = val_lo + val_hi;
1760- #ifndef XSIMD_NO_INFINITIES
1761- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1776+ #ifdef __FAST_MATH__
1777+ return r ;
17621778#else
1763- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1764- #endif
1779+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
17651780 return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1781+ #endif
17661782 }
17671783
17681784 template <class A , class T >
@@ -1805,12 +1821,12 @@ namespace xsimd
18051821 /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */
18061822 batch_type c = select (batch_bool_cast<float >(k >= i_type (2 )), batch_type (1 .) - (uf - self), self - (uf - batch_type (1 .))) / uf;
18071823 batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, (hfsq + R), dk * constants::log_2lo<batch_type>() + c) - hfsq + f);
1808- #ifndef XSIMD_NO_INFINITIES
1809- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1824+ #ifdef __FAST_MATH__
1825+ return r ;
18101826#else
1811- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1812- #endif
1827+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
18131828 return select (!(uf >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1829+ #endif
18141830 }
18151831
18161832 template <class A >
@@ -1838,12 +1854,12 @@ namespace xsimd
18381854 batch_type R = t2 + t1;
18391855 batch_type dk = to_float (k);
18401856 batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, hfsq + R, dk * constants::log_2lo<batch_type>() + c) - hfsq + f);
1841- #ifndef XSIMD_NO_INFINITIES
1842- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1857+ #ifdef __FAST_MATH__
1858+ return r ;
18431859#else
1844- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1845- #endif
1860+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
18461861 return select (!(uf >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1862+ #endif
18471863 }
18481864
18491865 template <class A , class T >
@@ -1980,13 +1996,21 @@ namespace xsimd
19801996 static XSIMD_INLINE batch_type next (const batch_type& b) noexcept
19811997 {
19821998 batch_type n = ::xsimd::bitwise_cast<T>(::xsimd::bitwise_cast<int_type>(b) + int_type (1 ));
1999+ #ifdef __FAST_MATH__
2000+ return n;
2001+ #else
19832002 return select (b == constants::infinity<batch_type>(), b, n);
2003+ #endif
19842004 }
19852005
19862006 static XSIMD_INLINE batch_type prev (const batch_type& b) noexcept
19872007 {
19882008 batch_type p = ::xsimd::bitwise_cast<T>(::xsimd::bitwise_cast<int_type>(b) - int_type (1 ));
2009+ #ifdef __FAST_MATH__
2010+ return p;
2011+ #else
19892012 return select (b == constants::minusinfinity<batch_type>(), b, p);
2013+ #endif
19902014 }
19912015 };
19922016 }
@@ -2355,10 +2379,12 @@ namespace xsimd
23552379 y *= v;
23562380 y = select (test, y, y * v);
23572381 y *= constants::sqrt_2pi<batch_type>() * w;
2358- #ifndef XSIMD_NO_INFINITIES
2382+ #ifdef __FAST_MATH__
2383+ return y;
2384+ #else
23592385 y = select (isinf (x), x, y);
2360- #endif
23612386 return select (x > stirlinglargelim, constants::infinity<batch_type>(), y);
2387+ #endif
23622388 }
23632389
23642390 /* origin: boost/simd/arch/common/detail/common/gamma_kernel.hpp */
@@ -2501,7 +2527,11 @@ namespace xsimd
25012527 }
25022528 batch_type r1 = detail::tgamma_other (self, test);
25032529 batch_type r2 = select (test, r, r1);
2530+ #ifdef __FAST_MATH__
2531+ return r2;
2532+ #else
25042533 return select (self == batch_type (0 .), copysign (constants::infinity<batch_type>(), self), select (nan_result, constants::nan<batch_type>(), r2));
2534+ #endif
25052535 }
25062536
25072537 }
0 commit comments