mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix plog(+INF): it returned ~87 instead of +INF
This commit is contained in:
@@ -54,6 +54,7 @@ Packet plog_float(const Packet _x)
|
|||||||
// The smallest non denormalized float number.
|
// The smallest non denormalized float number.
|
||||||
const Packet cst_min_norm_pos = pset1frombits<Packet>( 0x00800000u);
|
const Packet cst_min_norm_pos = pset1frombits<Packet>( 0x00800000u);
|
||||||
const Packet cst_minus_inf = pset1frombits<Packet>( 0xff800000u);
|
const Packet cst_minus_inf = pset1frombits<Packet>( 0xff800000u);
|
||||||
|
const Packet cst_pos_inf = pset1frombits<Packet>( 0x7f800000u);
|
||||||
|
|
||||||
// Polynomial coefficients.
|
// Polynomial coefficients.
|
||||||
const Packet cst_cephes_SQRTHF = pset1<Packet>(0.707106781186547524f);
|
const Packet cst_cephes_SQRTHF = pset1<Packet>(0.707106781186547524f);
|
||||||
@@ -69,9 +70,6 @@ Packet plog_float(const Packet _x)
|
|||||||
const Packet cst_cephes_log_q1 = pset1<Packet>(-2.12194440e-4f);
|
const Packet cst_cephes_log_q1 = pset1<Packet>(-2.12194440e-4f);
|
||||||
const Packet cst_cephes_log_q2 = pset1<Packet>(0.693359375f);
|
const Packet cst_cephes_log_q2 = pset1<Packet>(0.693359375f);
|
||||||
|
|
||||||
Packet invalid_mask = pcmp_lt_or_nan(x, pzero(x));
|
|
||||||
Packet iszero_mask = pcmp_eq(x,pzero(x));
|
|
||||||
|
|
||||||
// Truncate input values to the minimum positive normal.
|
// Truncate input values to the minimum positive normal.
|
||||||
x = pmax(x, cst_min_norm_pos);
|
x = pmax(x, cst_min_norm_pos);
|
||||||
|
|
||||||
@@ -117,8 +115,15 @@ Packet plog_float(const Packet _x)
|
|||||||
x = padd(x, y);
|
x = padd(x, y);
|
||||||
x = padd(x, y2);
|
x = padd(x, y2);
|
||||||
|
|
||||||
// Filter out invalid inputs, i.e. negative arg will be NAN, 0 will be -INF.
|
Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x));
|
||||||
return pselect(iszero_mask, cst_minus_inf, por(x, invalid_mask));
|
Packet iszero_mask = pcmp_eq(_x,pzero(_x));
|
||||||
|
Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf);
|
||||||
|
// Filter out invalid inputs, i.e.:
|
||||||
|
// - negative arg will be NAN
|
||||||
|
// - 0 will be -INF
|
||||||
|
// - +INF will be +INF
|
||||||
|
return pselect(iszero_mask, cst_minus_inf,
|
||||||
|
por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exponential function. Works by writing "x = m*log(2) + r" where
|
// Exponential function. Works by writing "x = m*log(2) + r" where
|
||||||
|
|||||||
@@ -520,10 +520,11 @@ template<typename Scalar,typename Packet> void packetmath_real()
|
|||||||
CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErfc, std::erfc, internal::perfc);
|
CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErfc, std::erfc, internal::perfc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(PacketTraits::HasLog && PacketSize>=2)
|
if(PacketSize>=2)
|
||||||
{
|
{
|
||||||
data1[0] = std::numeric_limits<Scalar>::quiet_NaN();
|
data1[0] = std::numeric_limits<Scalar>::quiet_NaN();
|
||||||
data1[1] = std::numeric_limits<Scalar>::epsilon();
|
data1[1] = std::numeric_limits<Scalar>::epsilon();
|
||||||
|
if(PacketTraits::HasLog)
|
||||||
{
|
{
|
||||||
packet_helper<PacketTraits::HasLog,Packet> h;
|
packet_helper<PacketTraits::HasLog,Packet> h;
|
||||||
h.store(data2, internal::plog(h.load(data1)));
|
h.store(data2, internal::plog(h.load(data1)));
|
||||||
@@ -551,6 +552,10 @@ template<typename Scalar,typename Packet> void packetmath_real()
|
|||||||
data1[0] = Scalar(-1.0f);
|
data1[0] = Scalar(-1.0f);
|
||||||
h.store(data2, internal::plog(h.load(data1)));
|
h.store(data2, internal::plog(h.load(data1)));
|
||||||
VERIFY((numext::isnan)(data2[0]));
|
VERIFY((numext::isnan)(data2[0]));
|
||||||
|
|
||||||
|
data1[0] = std::numeric_limits<Scalar>::infinity();
|
||||||
|
h.store(data2, internal::plog(h.load(data1)));
|
||||||
|
VERIFY((numext::isinf)(data2[0]));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
packet_helper<PacketTraits::HasSqrt,Packet> h;
|
packet_helper<PacketTraits::HasSqrt,Packet> h;
|
||||||
|
|||||||
Reference in New Issue
Block a user