Ejemplo n.º 1
0
static void
test_behavior ()
{
    union {
        float       f;
        double      d;

#ifndef _RWSTD_NO_LONG_DOUBLE
        long double l;
#endif   // _RWSTD_NO_LONG_DOUBLE

        char buf [sizeof (long double) * 2];
    } u;

#if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    // make sure functions do not overflow buffer
    clear_bytes (u.buf, sizeof u);
    const float f = std::modf (3.141592f, &u.f);
    if(!( 3000 == int (u.f * 1000) && 141592 == int (f * 1000000)
               && check_bits (u.buf + sizeof u.f, sizeof u - sizeof u.f))) 
     {
       failures++;
       std_log(LOG_FILENAME_LINE,"Reason: Failing modf function");
      }
  
      rw_assert (   3000 == int (u.f * 1000) && 141592 == int (f * 1000000)
               && check_bits (u.buf + sizeof u.f, sizeof u - sizeof u.f),
               0, __LINE__, "float std::modf (float)");

#endif   // SunPro > 5.3

    clear_bytes (u.buf, sizeof u);
    const double d = std::modf (3.1415926, &u.d);
    
    if(!(3000 == int (u.d * 1000) && 1415926 == int (d * 10000000)
               && check_bits (u.buf + sizeof u.d, sizeof u - sizeof u.d))) 
     {
       failures++;
       std_log(LOG_FILENAME_LINE,"Reason: Failing modf function");
      }
    rw_assert (   3000 == int (u.d * 1000) && 1415926 == int (d * 10000000)
               && check_bits (u.buf + sizeof u.d, sizeof u - sizeof u.d),
               0, __LINE__, "double std::modf (double)");

#ifndef __SYMBIAN32__
#ifndef _RWSTD_NO_LONG_DOUBLE

#  if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    clear_bytes (u.buf, sizeof u);
    const long double l = std::modf (3.1415926L, &u.l);
     bool test=check_bits (u.buf + sizeof u.l, sizeof u - sizeof u.l);
     if(!(3000 == int (u.l * 1000) && 1415926 == int (l * 10000000)
               && test)) 
     {
       failures++;
       std_log(LOG_FILENAME_LINE,"Reason: Failing modf function");
      }
    rw_assert (   3000 == int (u.l * 1000) && 1415926 == int (l * 10000000)
               && check_bits (u.buf + sizeof u.l, sizeof u - sizeof u.l),
               0, __LINE__, "long double std::modf (long double)");

#  endif   // SunPro > 5.3

#endif   // _RWSTD_NO_LONG_DOUBLE
#endif // __SYMBIAN32__


    // check overloads of std::pow()
    for (int i = -10; i != 10; ++i) {
        for (int j = -10; j != 10; ++j) {

            if (-9 < j && j < 9) {
                // verify that both versions are equivalent
                const float xf = std::pow (float (i), int (j));
                const float yf = std::pow (float (i), float (j));
                       
                 if(!(rw_equal (xf, yf) || !i && j < 0))
                 {
                   failures++;
                   std_log(LOG_FILENAME_LINE,"Reason: Failing pow function for i=%d,j=%d",i,j);
                 }
                  
                rw_assert (rw_equal (xf, yf) || !i && j < 0,
                           0, __LINE__,
                           "std::pow (%d.0f, %d) = %g, "
                           "std::pow (%d,0f, %d.0f) = %g",
                           i, j, xf, i, j, yf);
            }

            const float xd = std::pow (double (i), int (j));
            const float yd = std::pow (double (i), double (j));

			  if(!(rw_equal (xd, yd) || !i && j < 0))
			                 {
			                   failures++;
			                    std_log(LOG_FILENAME_LINE,"Reason: Failing pow function for i=%d,j=%d",i,j);
			                 }

            rw_assert (rw_equal (xd, yd) || !i && j < 0,
                       0, __LINE__,
                       "std::pow (%d.0, %d) = %g, "
                       "std::pow (%d.0, %d.0) = %g",
                       i, j, xd, i, j, yd);

#ifndef _RWSTD_NO_LONG_DOUBLE

            const long double xl = std::pow ((long double)i, int (j));
            const long double yl = std::pow ((long double)i, (long double)j);
            
            if(!(rw_equal (xl, yl) || !i && j < 0))
			                 {
			                   failures++;
			                    std_log(LOG_FILENAME_LINE,"Reason: Failing pow function ");
			                 }

        
            rw_assert (rw_equal (xl, yl) || !i && j < 0,
                       0, __LINE__,
                       "std::pow (%d.0L, %d) = %Lg, "
                       "std::pow (%d.0L, %d.0L) = %Lg",
                       i, j, xl, i, j, yl);

#endif   // _RWSTD_NO_LONG_DOUBLE

        }
    }
}
Ejemplo n.º 2
0
static void
test_behavior ()
{
    union {
        float       f;
        double      d;

#ifndef _RWSTD_NO_LONG_DOUBLE
        long double l;
#endif   // _RWSTD_NO_LONG_DOUBLE

        char buf [sizeof (long double) * 2];
    } u;

#if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    // make sure functions do not overflow buffer
    clear_bytes (u.buf, sizeof u);

    const float f = std::modf (3.141592f, &u.f);

    rw_assert (   3000 == int (u.f * 1000) && 141592 == int (f * 1000000)
               && check_bits (u.buf + sizeof (u.f), sizeof (u) - sizeof (u.f)),
               __FILE__, __LINE__, "float std::modf (float)");

#endif   // SunPro > 5.3

    clear_bytes (u.buf, sizeof u);
    const double d = std::modf (3.1415926, &u.d);

    rw_assert (   3000 == int (u.d * 1000) && 1415926 == int (d * 10000000)
               && check_bits (u.buf + sizeof (u.d), sizeof (u) - sizeof (u.d)),
               __FILE__, __LINE__, "double std::modf (double)");

#ifndef _RWSTD_NO_LONG_DOUBLE

#  if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    clear_bytes (u.buf, sizeof u);
    const long double l = std::modf (3.1415926L, &u.l);

    rw_assert (   3000 == int (u.l * 1000) && 1415926 == int (l * 10000000)
               && check_bits (u.buf + sizeof (u.l), sizeof (u) - sizeof (u.l)),
               __FILE__, __LINE__, "long double std::modf (long double)");

#  endif   // SunPro > 5.3

#endif   // _RWSTD_NO_LONG_DOUBLE

    // check overloads of std::pow()
    for (int i = -10; i != 10; ++i) {

        for (int j = -10; j != 10; ++j) {

            if (-9 < j && j < 9) {
                const float fi = float (i);
                const float fj = float (j);

                // verify that both versions are equivalent
                const float xf = std::pow (fi, j);
                const float yf = std::pow (fi, fj);

                rw_assert (rw_equal (xf, yf) || (!i && j < 0),
                           0, __LINE__,
                           "std::pow (%d.0f, %d) = %g, "
                           "std::pow (%d,0f, %d.0f) = %g",
                           i, j, xf, i, j, yf);
            }

            const double id = double (i);
            const double jd = double (j);

            const double xd = std::pow (id, j);
            const double yd = std::pow (id, jd);

            rw_assert (rw_equal (xd, yd) || (!i && j < 0),
                       0, __LINE__,
                       "std::pow (%d.0, %d) = %g, "
                       "std::pow (%d.0, %d.0) = %g",
                       i, j, xd, i, j, yd);

#ifndef _RWSTD_NO_LONG_DOUBLE

            const long double il = _RWSTD_STATIC_CAST (long double, i);
            const long double jl = _RWSTD_STATIC_CAST (long double, j);

            const long double xl = std::pow (il, j);
            const long double yl = std::pow (il, jl);

            rw_assert (rw_equal (xl, yl) || (!i && j < 0),
                       0, __LINE__,
                       "std::pow (%d.0L, %d) = %Lg, "
                       "std::pow (%d.0L, %d.0L) = %Lg",
                       i, j, xl, i, j, yl);

#endif   // _RWSTD_NO_LONG_DOUBLE

        }
    }
}