コード例 #1
0
ファイル: arith11.c プロジェクト: webushka/reduce
static CSLbool numeqsr(Lisp_Object a, Lisp_Object b)
/*
 * Here I will rely somewhat on the use of IEEE floating point values
 * (an in particular the weaker supposition that I have floating point
 * with a binary radix).  Then for equality the denominator of b must
 * be a power of 2, which I can test for and then account for.
 */
{
    Lisp_Object nb = numerator(b), db = denominator(b);
    double d = float_of_number(a), d1;
    int x;
    int32_t dx, w, len;
    uint32_t u, bit;
    /*
     * first I will check that db (which will be positive) is a power of 2,
     * and set dx to indicate what power of two it is.
     * Note that db != 0 and that one of the top two words of a bignum
     * must be nonzero (for normalisation) so I end up with a nonzero
     * value in the variable 'bit'
     */
    if (is_fixnum(db))
    {   bit = int_of_fixnum(db);
        w = bit;
        if (w != (w & (-w))) return NO;   /* not a power of 2 */
        dx = 0;
    }
    else if (is_numbers(db) && is_bignum(db))
    {   int32_t lenb = (bignum_length(db)-CELL-4)/4;
        bit = bignum_digits(db)[lenb];
        /*
         * I need to cope with bignums where the leading digits is zero because
         * the 0x80000000 bit of the next word down is 1.  To do this I treat
         * the number as having one fewer digits.
         */
        if (bit == 0) bit = bignum_digits(db)[--lenb];
        w = bit;
        if (w != (w & (-w))) return NO;   /* not a power of 2 */
        dx = 31*lenb;
        while (--lenb >= 0)     /* check that the rest of db is zero */
            if (bignum_digits(db)[lenb] != 0) return NO;
    }
    else return NO; /* Odd - what type IS db here?  Maybe error. */
    if ((bit & 0xffffU) == 0) dx += 16, bit = bit >> 16;
    if ((bit & 0xff) == 0) dx += 8, bit = bit >> 8;
    if ((bit & 0xf) == 0) dx += 4, bit = bit >> 4;
    if ((bit & 0x3) == 0) dx += 2, bit = bit >> 2;
    if ((bit & 0x1) == 0) dx += 1;
    if (is_fixnum(nb))
    {   double d1 = (double)int_of_fixnum(nb);
        /*
         * The ldexp on the next line could potentially underflow.  In that case C
         * defines that the result 0.0 be returned.  To avoid trouble I put in a
         * special test the relies on that fact that a value represented as a rational
         * would not have been zero.
         */
        if (dx > 10000) return NO;  /* Avoid gross underflow */
        d1 = ldexp(d1, (int)-dx);
        return (d == d1 && d != 0.0);
    }
    len = (bignum_length(nb)-CELL-4)/4;
    if (len == 0)   /* One word bignums can be treated specially */
    {   int32_t v = bignum_digits(nb)[0];
        double d1;
        if (dx > 10000) return NO;  /* Avoid gross underflow */
        d1 = ldexp((double)v, (int)-dx);
        return (d == d1 && d != 0.0);
    }
    d1 = frexp(d, &x);    /* separate exponent from mantissa */
    if (d1 == 1.0) d1 = 0.5, x++; /* For Zortech */
    dx += x;              /* adjust to allow for the denominator */
    d1 = ldexp(d1, (int)(dx % 31));
    /* can neither underflow nor overflow here */
    /*
     * At most 3 words in the bignum may contain nonzero data - I subtract
     * the (double) value of those bits off and check that (a) the floating
     * result left is zero and (b) there are no more bits left.
     */
    dx = dx / 31;
    if (dx != len) return NO;
    w = bignum_digits(nb)[len];
    d1 = (d1 - (double)w) * TWO_31;
    u = bignum_digits(nb)[--len];
    d1 = (d1 - (double)u) * TWO_31;
    if (len > 0)
    {   u = bignum_digits(nb)[--len];
        d1 = d1 - (double)u;
    }
    if (d1 != 0.0) return NO;
    while (--len >= 0)
        if (bignum_digits(nb)[len] != 0) return NO;
    return YES;
}
コード例 #2
0
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "KoPathSegment.h"
#include "KoPathPoint.h"
#include <FlakeDebug.h>
#include <QPainterPath>
#include <QTransform>
#include <math.h>

/// Maximal recursion depth for finding root params
const int MaxRecursionDepth = 64;
/// Flatness tolerance for finding root params
const qreal FlatnessTolerance = ldexp(1.0,-MaxRecursionDepth-1);

class BezierSegment
{
public:
    BezierSegment(int degree = 0, QPointF *p = 0)
    {
        if (degree) {
            for (int i = 0; i <= degree; ++i)
                points.append(p[i]);
        }
    }

    void setDegree(int degree)
    {
        points.clear();
コード例 #3
0
ファイル: test_nc_beta.hpp プロジェクト: wilsonCernWq/Simula
void quantile_sanity_check(T& data, const char* type_name, const char* test)
{
#ifndef ERROR_REPORTING_MODE
    typedef Real                   value_type;

    //
    // Tests with type real_concept take rather too long to run, so
    // for now we'll disable them:
    //
    if(!boost::is_floating_point<value_type>::value)
        return;

    std::cout << "Testing: " << type_name << " quantile sanity check, with tests " << test << std::endl;

    //
    // These sanity checks test for a round trip accuracy of one half
    // of the bits in T, unless T is type float, in which case we check
    // for just one decimal digit.  The problem here is the sensitivity
    // of the functions, not their accuracy.  This test data was generated
    // for the forward functions, which means that when it is used as
    // the input to the inverses then it is necessarily inexact.  This rounding
    // of the input is what makes the data unsuitable for use as an accuracy check,
    // and also demonstrates that you can't in general round-trip these functions.
    // It is however a useful sanity check.
    //
    value_type precision = static_cast<value_type>(ldexp(1.0, 1 - boost::math::policies::digits<value_type, boost::math::policies::policy<> >() / 2)) * 100;
    if(boost::math::policies::digits<value_type, boost::math::policies::policy<> >() < 50)
        precision = 1;   // 1% or two decimal digits, all we can hope for when the input is truncated to float

    for(unsigned i = 0; i < data.size(); ++i)
    {
        //
        // Test case 493 fails at float precision: not enough bits to get
        // us back where we started:
        //
        if((i == 493) && boost::is_same<float, value_type>::value)
            continue;

        if(data[i][4] == 0)
        {
            BOOST_CHECK(0 == quantile(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][4]));
        }
        else if(data[i][4] < 0.9999f)
        {
            value_type p = quantile(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][4]);
            value_type pt = data[i][3];
            BOOST_CHECK_CLOSE_EX(pt, p, precision, i);
        }
        if(data[i][5] == 0)
        {
            BOOST_CHECK(1 == quantile(complement(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][5])));
        }
        else if(data[i][5] < 0.9999f)
        {
            value_type p = quantile(complement(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][5]));
            value_type pt = data[i][3];
            BOOST_CHECK_CLOSE_EX(pt, p, precision, i);
        }
        if(boost::math::tools::digits<value_type>() > 50)
        {
            //
            // Sanity check mode, accuracy of
            // the mode is at *best* the square root of the accuracy of the PDF:
            //
            value_type m = mode(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]));
            if((m == 1) || (m == 0))
                break;
            value_type p = pdf(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), m);
            if(m * (1 + sqrt(precision) * 10) < 1)
            {
                BOOST_CHECK_EX(pdf(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), m * (1 + sqrt(precision) * 10)) <= p, i);
            }
            if(m * (1 - sqrt(precision)) * 10 > boost::math::tools::min_value<value_type>())
            {
                BOOST_CHECK_EX(pdf(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), m * (1 - sqrt(precision)) * 10) <= p, i);
            }
        }
    }
#endif
}
コード例 #4
0
  const FixedPointType& tolerance_maker(const int fuzzy_bits)
  {
    static const FixedPointType the_tolerance = ldexp(FixedPointType(1), FixedPointType::resolution + fuzzy_bits);

    return the_tolerance;
  }
コード例 #5
0
ファイル: lmathlib.c プロジェクト: jiangguang5201314/ZNginx
static int math_ldexp (lua_State *L)
{
    lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
    return 1;
}
コード例 #6
0
ファイル: stubs.c プロジェクト: Fokycnuk/gcc
float
ldexpf(float x, int exp)
{
  return (float) ldexp(x, exp);
}
コード例 #7
0
inline T epsilon(const mpl::false_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T))
{
   BOOST_MATH_STD_USING  // for ADL of std names
   static const T eps = ldexp(static_cast<T>(1), 1-policies::digits<T, policies::policy<> >());
   return eps;
}
コード例 #8
0
ファイル: meshing.cpp プロジェクト: NickProkharau/GSOC2015
//
// sample script to create volumetric mesh from
//  multiple levelsets of a binary segmented head image.
// Arguments    : void
// Return Type  : void
//
static void c_meshing()
{
  double fid;
  static double face[362368];
  static double elem[565750];
  static double node[100564];
  static int idx[113150];
  int k;
  boolean_T p;
  static int idx0[113150];
  int i;
  int i2;
  int j;
  int pEnd;
  int nb;
  int b_k;
  int qEnd;
  int kEnd;
  emxArray_real_T *b;
  double x;
  int32_T exitg1;
  int exponent;
  emxArray_real_T *b_b;

  //  create volumetric tetrahedral mesh from the two-layer 3D images
  //  head surface element size bound  
  b_fprintf();

	TCHAR pwd[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,pwd);
	std::string str= pwd;	
	std::string const command=char(34)+str+"\\bin\\cgalmesh.exe" +char(34)+" pre_cgalmesh.inr post_cgalmesh.mesh 30 4 0.5 3 100 1648335518";
	system(command.c_str());
	
  b_readmedit(node, elem, face);

  // node=node*double(vol(1,1,1));
  for (k = 0; k < 113150; k++) {
    idx[k] = k + 1;
  }

  for (k = 0; k < 113150; k += 2) {
    if ((elem[452600 + k] <= elem[k + 452601]) || rtIsNaN(elem[k + 452601])) {
      p = true;
    } else {
      p = false;
    }

    if (p) {
    } else {
      idx[k] = k + 2;
      idx[k + 1] = k + 1;
    }
  }

  for (i = 0; i < 113150; i++) {
    idx0[i] = 1;
  }

  i = 2;
  while (i < 113150) {
    i2 = i << 1;
    j = 1;
    for (pEnd = 1 + i; pEnd < 113151; pEnd = qEnd + i) {
      nb = j;
      b_k = pEnd - 1;
      qEnd = j + i2;
      if (qEnd > 113151) {
        qEnd = 113151;
      }

      k = 0;
      kEnd = qEnd - j;
      while (k + 1 <= kEnd) {
        if ((elem[idx[nb - 1] + 452599] <= elem[idx[b_k] + 452599]) || rtIsNaN
            (elem[idx[b_k] + 452599])) {
          p = true;
        } else {
          p = false;
        }

        if (p) {
          idx0[k] = idx[nb - 1];
          nb++;
          if (nb == pEnd) {
            while (b_k + 1 < qEnd) {
              k++;
              idx0[k] = idx[b_k];
              b_k++;
            }
          }
        } else {
          idx0[k] = idx[b_k];
          b_k++;
          if (b_k + 1 == qEnd) {
            while (nb < pEnd) {
              k++;
              idx0[k] = idx[nb - 1];
              nb++;
            }
          }
        }

        k++;
      }

      for (k = 0; k + 1 <= kEnd; k++) {
        idx[(j + k) - 1] = idx0[k];
      }

      j = qEnd;
    }

    i = i2;
  }

  emxInit_real_T(&b, 1);
  i2 = b->size[0];
  b->size[0] = 113150;
  emxEnsureCapacity((emxArray__common *)b, i2, (int)sizeof(double));
  for (k = 0; k < 113150; k++) {
    b->data[k] = elem[idx[k] + 452599];
  }

  k = 0;
  while ((k + 1 <= 113150) && rtIsInf(b->data[k]) && (b->data[k] < 0.0)) {
    k++;
  }

  b_k = k;
  k = 113150;
  while ((k >= 1) && rtIsNaN(b->data[k - 1])) {
    k--;
  }

  pEnd = 113150 - k;
  while ((k >= 1) && rtIsInf(b->data[k - 1]) && (b->data[k - 1] > 0.0)) {
    k--;
  }

  i2 = 113150 - (k + pEnd);
  nb = -1;
  if (b_k > 0) {
    nb = 0;
  }

  i = (b_k + k) - b_k;
  while (b_k + 1 <= i) {
    x = b->data[b_k];
    do {
      exitg1 = 0;
      b_k++;
      if (b_k + 1 > i) {
        exitg1 = 1;
      } else {
        fid = fabs(x / 2.0);
        if ((!rtIsInf(fid)) && (!rtIsNaN(fid))) {
          if (fid <= 2.2250738585072014E-308) {
            fid = 4.94065645841247E-324;
          } else {
            frexp(fid, &exponent);
            fid = ldexp(1.0, exponent - 53);
          }
        } else {
          fid = rtNaN;
        }

        if ((fabs(x - b->data[b_k]) < fid) || (rtIsInf(b->data[b_k]) && rtIsInf
             (x) && ((b->data[b_k] > 0.0) == (x > 0.0)))) {
          p = true;
        } else {
          p = false;
        }

        if (!p) {
          exitg1 = 1;
        }
      }
    } while (exitg1 == 0);

    nb++;
    b->data[nb] = x;
  }

  if (i2 > 0) {
    nb++;
    b->data[nb] = b->data[i];
  }

  b_k = i + i2;
  for (j = 1; j <= pEnd; j++) {
    nb++;
    b->data[nb] = b->data[(b_k + j) - 1];
  }

  if (1 > nb + 1) {
    i = -1;
  } else {
    i = nb;
  }

  emxInit_real_T(&b_b, 1);
  i2 = b_b->size[0];
  b_b->size[0] = i + 1;
  emxEnsureCapacity((emxArray__common *)b_b, i2, (int)sizeof(double));
  for (i2 = 0; i2 <= i; i2++) {
    b_b->data[i2] = b->data[i2];
  }

  i2 = b->size[0];
  b->size[0] = b_b->size[0];
  emxEnsureCapacity((emxArray__common *)b, i2, (int)sizeof(double));
  i = b_b->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b->data[i2] = b_b->data[i2];
  }

  emxFree_real_T(&b_b);
  c_fprintf((double)b->size[0]);
  d_fprintf();
  emxFree_real_T(&b);
}
コード例 #9
0
ファイル: test-invtrig.c プロジェクト: JabirTech/Source
/*
 * Test special case inputs in atan2(), where the exact value of y/x is
 * zero or non-finite.
 */
static void
test_special_atan2(void)
{
	long double z;
	int e;

	testall2(atan2, 0.0, -0.0, pi, FE_INEXACT);
	testall2(atan2, -0.0, -0.0, -pi, FE_INEXACT);
	testall2(atan2, 0.0, 0.0, 0.0, 0);
	testall2(atan2, -0.0, 0.0, -0.0, 0);

	testall2(atan2, INFINITY, -INFINITY, c3pi / 4, FE_INEXACT);
	testall2(atan2, -INFINITY, -INFINITY, -c3pi / 4, FE_INEXACT);
	testall2(atan2, INFINITY, INFINITY, pi / 4, FE_INEXACT);
	testall2(atan2, -INFINITY, INFINITY, -pi / 4, FE_INEXACT);

	/* Tests with one input in the range (0, Inf]. */
	z = 1.23456789L;
	for (e = FLT_MIN_EXP - FLT_MANT_DIG; e <= FLT_MAX_EXP; e++) {
		test2(atan2f, 0.0, ldexpf(z, e), 0.0, 0);
		test2(atan2f, -0.0, ldexpf(z, e), -0.0, 0);
		test2(atan2f, 0.0, ldexpf(-z, e), (float)pi, FE_INEXACT);
		test2(atan2f, -0.0, ldexpf(-z, e), (float)-pi, FE_INEXACT);
		test2(atan2f, ldexpf(z, e), 0.0, (float)pi / 2, FE_INEXACT);
		test2(atan2f, ldexpf(z, e), -0.0, (float)pi / 2, FE_INEXACT);
		test2(atan2f, ldexpf(-z, e), 0.0, (float)-pi / 2, FE_INEXACT);
		test2(atan2f, ldexpf(-z, e), -0.0, (float)-pi / 2, FE_INEXACT);
	}
	for (e = DBL_MIN_EXP - DBL_MANT_DIG; e <= DBL_MAX_EXP; e++) {
		test2(atan2, 0.0, ldexp(z, e), 0.0, 0);
		test2(atan2, -0.0, ldexp(z, e), -0.0, 0);
		test2(atan2, 0.0, ldexp(-z, e), (double)pi, FE_INEXACT);
		test2(atan2, -0.0, ldexp(-z, e), (double)-pi, FE_INEXACT);
		test2(atan2, ldexp(z, e), 0.0, (double)pi / 2, FE_INEXACT);
		test2(atan2, ldexp(z, e), -0.0, (double)pi / 2, FE_INEXACT);
		test2(atan2, ldexp(-z, e), 0.0, (double)-pi / 2, FE_INEXACT);
		test2(atan2, ldexp(-z, e), -0.0, (double)-pi / 2, FE_INEXACT);
	}
	for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e <= LDBL_MAX_EXP; e++) {
		test2(atan2l, 0.0, ldexpl(z, e), 0.0, 0);
		test2(atan2l, -0.0, ldexpl(z, e), -0.0, 0);
		test2(atan2l, 0.0, ldexpl(-z, e), pi, FE_INEXACT);
		test2(atan2l, -0.0, ldexpl(-z, e), -pi, FE_INEXACT);
		test2(atan2l, ldexpl(z, e), 0.0, pi / 2, FE_INEXACT);
		test2(atan2l, ldexpl(z, e), -0.0, pi / 2, FE_INEXACT);
		test2(atan2l, ldexpl(-z, e), 0.0, -pi / 2, FE_INEXACT);
		test2(atan2l, ldexpl(-z, e), -0.0, -pi / 2, FE_INEXACT);
	}

	/* Tests with one input in the range (0, Inf). */
	for (e = FLT_MIN_EXP - FLT_MANT_DIG; e <= FLT_MAX_EXP - 1; e++) {
		test2(atan2f, ldexpf(z, e), INFINITY, 0.0, 0);
		test2(atan2f, ldexpf(-z,e), INFINITY, -0.0, 0);
		test2(atan2f, ldexpf(z, e), -INFINITY, (float)pi, FE_INEXACT);
		test2(atan2f, ldexpf(-z,e), -INFINITY, (float)-pi, FE_INEXACT);
		test2(atan2f, INFINITY, ldexpf(z,e), (float)pi/2, FE_INEXACT);
		test2(atan2f, INFINITY, ldexpf(-z,e), (float)pi/2, FE_INEXACT);
		test2(atan2f, -INFINITY, ldexpf(z,e), (float)-pi/2,FE_INEXACT);
		test2(atan2f, -INFINITY, ldexpf(-z,e),(float)-pi/2,FE_INEXACT);
	}
	for (e = DBL_MIN_EXP - DBL_MANT_DIG; e <= DBL_MAX_EXP - 1; e++) {
		test2(atan2, ldexp(z, e), INFINITY, 0.0, 0);
		test2(atan2, ldexp(-z,e), INFINITY, -0.0, 0);
		test2(atan2, ldexp(z, e), -INFINITY, (double)pi, FE_INEXACT);
		test2(atan2, ldexp(-z,e), -INFINITY, (double)-pi, FE_INEXACT);
		test2(atan2, INFINITY, ldexp(z,e), (double)pi/2, FE_INEXACT);
		test2(atan2, INFINITY, ldexp(-z,e), (double)pi/2, FE_INEXACT);
		test2(atan2, -INFINITY, ldexp(z,e), (double)-pi/2,FE_INEXACT);
		test2(atan2, -INFINITY, ldexp(-z,e),(double)-pi/2,FE_INEXACT);
	}
	for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e <= LDBL_MAX_EXP - 1; e++) {
		test2(atan2l, ldexpl(z, e), INFINITY, 0.0, 0);
		test2(atan2l, ldexpl(-z,e), INFINITY, -0.0, 0);
		test2(atan2l, ldexpl(z, e), -INFINITY, pi, FE_INEXACT);
		test2(atan2l, ldexpl(-z,e), -INFINITY, -pi, FE_INEXACT);
		test2(atan2l, INFINITY, ldexpl(z, e), pi / 2, FE_INEXACT);
		test2(atan2l, INFINITY, ldexpl(-z, e), pi / 2, FE_INEXACT);
		test2(atan2l, -INFINITY, ldexpl(z, e), -pi / 2, FE_INEXACT);
		test2(atan2l, -INFINITY, ldexpl(-z, e), -pi / 2, FE_INEXACT);
	}
}
コード例 #10
0
ファイル: roots.hpp プロジェクト: 3DJ/ofxOgre
T schroeder_iterate(F f, T guess, T min, T max, int digits, boost::uintmax_t& max_iter)
{
   BOOST_MATH_STD_USING

   T f0(0), f1, f2, last_f0(0);
   T result = guess;

   T factor = static_cast<T>(ldexp(1.0, 1 - digits));
   T delta = 0;
   T delta1 = tools::max_value<T>();
   T delta2 = tools::max_value<T>();

#ifdef BOOST_MATH_INSTRUMENT
   std::cout << "Schroeder iteration, limit = " << factor << std::endl;
#endif

   boost::uintmax_t count(max_iter);

   do{
      last_f0 = f0;
      delta2 = delta1;
      delta1 = delta;
      boost::math::tie(f0, f1, f2) = f(result);
      if(0 == f0)
         break;
      if((f1 == 0) && (f2 == 0))
      {
         // Oops zero derivative!!!
#ifdef BOOST_MATH_INSTRUMENT
         std::cout << "Halley iteration, zero derivative found" << std::endl;
#endif
         detail::handle_zero_derivative(f, last_f0, f0, delta, result, guess, min, max);
      }
      else
      {
         T ratio = f0 / f1;
         if(ratio / result < 0.1)
         {
            delta = ratio + (f2 / (2 * f1)) * ratio * ratio;
            // check second derivative doesn't over compensate:
            if(delta * ratio < 0)
               delta = ratio;
         }
         else
            delta = ratio;  // fall back to Newton iteration.
      }
      if(fabs(delta * 2) > fabs(delta2))
      {
         // last two steps haven't converged, try bisection:
         delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
      }
      guess = result;
      result -= delta;
#ifdef BOOST_MATH_INSTRUMENT
      std::cout << "Halley iteration, delta = " << delta << std::endl;
#endif
      if(result <= min)
      {
         delta = 0.5F * (guess - min);
         result = guess - delta;
         if((result == min) || (result == max))
            break;
      }
      else if(result >= max)
      {
         delta = 0.5F * (guess - max);
         result = guess - delta;
         if((result == min) || (result == max))
            break;
      }
      // update brackets:
      if(delta > 0)
         max = guess;
      else
         min = guess;
   }while(--count && (fabs(result * factor) < fabs(delta)));

   max_iter -= count;

#ifdef BOOST_MATH_INSTRUMENT
   std::cout << "Schroeder iteration, final count = " << max_iter << std::endl;

   static boost::uintmax_t max_count = 0;
   if(max_iter > max_count)
   {
      max_count = max_iter;
      std::cout << "Maximum iterations: " << max_iter << std::endl;
   }
#endif

   return result;
}
コード例 #11
0
ファイル: prim.c プロジェクト: masquerade0324/smlsharp
float ldexpf(float x, int n)
{
	return ldexp(x, n);
}
コード例 #12
0
ファイル: roots.hpp プロジェクト: 3DJ/ofxOgre
T halley_iterate(F f, T guess, T min, T max, int digits, boost::uintmax_t& max_iter)
{
   BOOST_MATH_STD_USING

   T f0(0), f1, f2;
   T result = guess;

   T factor = static_cast<T>(ldexp(1.0, 1 - digits));
   T delta = (std::max)(T(10000000 * guess), T(10000000));  // arbitarily large delta
   T last_f0 = 0;
   T delta1 = delta;
   T delta2 = delta;

   bool out_of_bounds_sentry = false;

#ifdef BOOST_MATH_INSTRUMENT
   std::cout << "Halley iteration, limit = " << factor << std::endl;
#endif

   boost::uintmax_t count(max_iter);

   do{
      last_f0 = f0;
      delta2 = delta1;
      delta1 = delta;
      boost::math::tie(f0, f1, f2) = f(result);

      BOOST_MATH_INSTRUMENT_VARIABLE(f0);
      BOOST_MATH_INSTRUMENT_VARIABLE(f1);
      BOOST_MATH_INSTRUMENT_VARIABLE(f2);
      
      if(0 == f0)
         break;
      if((f1 == 0) && (f2 == 0))
      {
         // Oops zero derivative!!!
#ifdef BOOST_MATH_INSTRUMENT
         std::cout << "Halley iteration, zero derivative found" << std::endl;
#endif
         detail::handle_zero_derivative(f, last_f0, f0, delta, result, guess, min, max);
      }
      else
      {
         if(f2 != 0)
         {
            T denom = 2 * f0;
            T num = 2 * f1 - f0 * (f2 / f1);

            BOOST_MATH_INSTRUMENT_VARIABLE(denom);
            BOOST_MATH_INSTRUMENT_VARIABLE(num);

            if((fabs(num) < 1) && (fabs(denom) >= fabs(num) * tools::max_value<T>()))
            {
               // possible overflow, use Newton step:
               delta = f0 / f1;
            }
            else
               delta = denom / num;
            if(delta * f1 / f0 < 0)
            {
               // probably cancellation error, try a Newton step instead:
               delta = f0 / f1;
            }
         }
         else
            delta = f0 / f1;
      }
#ifdef BOOST_MATH_INSTRUMENT
      std::cout << "Halley iteration, delta = " << delta << std::endl;
#endif
      T convergence = fabs(delta / delta2);
      if((convergence > 0.8) && (convergence < 2))
      {
         // last two steps haven't converged, try bisection:
         delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
         if(fabs(delta) > result)
            delta = sign(delta) * result; // protect against huge jumps!
         // reset delta2 so that this branch will *not* be taken on the
         // next iteration:
         delta2 = delta * 3;
         BOOST_MATH_INSTRUMENT_VARIABLE(delta);
      }
      guess = result;
      result -= delta;
      BOOST_MATH_INSTRUMENT_VARIABLE(result);

      // check for out of bounds step:
      if(result < min)
      {
         T diff = ((fabs(min) < 1) && (fabs(result) > 1) && (tools::max_value<T>() / fabs(result) < fabs(min))) ? T(1000)  : T(result / min);
         if(fabs(diff) < 1)
            diff = 1 / diff;
         if(!out_of_bounds_sentry && (diff > 0) && (diff < 3))
         {
            // Only a small out of bounds step, lets assume that the result
            // is probably approximately at min:
            delta = 0.99f * (guess  - min);
            result = guess - delta;
            out_of_bounds_sentry = true; // only take this branch once!
         }
         else
         {
            delta = (guess - min) / 2;
            result = guess - delta;
            if((result == min) || (result == max))
               break;
         }
      }
      else if(result > max)
      {
         T diff = ((fabs(max) < 1) && (fabs(result) > 1) && (tools::max_value<T>() / fabs(result) < fabs(max))) ? T(1000) : T(result / max);
         if(fabs(diff) < 1)
            diff = 1 / diff;
         if(!out_of_bounds_sentry && (diff > 0) && (diff < 3))
         {
            // Only a small out of bounds step, lets assume that the result
            // is probably approximately at min:
            delta = 0.99f * (guess  - max);
            result = guess - delta;
            out_of_bounds_sentry = true; // only take this branch once!
         }
         else
         {
            delta = (guess - max) / 2;
            result = guess - delta;
            if((result == min) || (result == max))
               break;
         }
      }
      // update brackets:
      if(delta > 0)
         max = guess;
      else
         min = guess;
   }while(--count && (fabs(result * factor) < fabs(delta)));

   max_iter -= count;

#ifdef BOOST_MATH_INSTRUMENT
   std::cout << "Halley iteration, final count = " << max_iter << std::endl;
#endif

   return result;
}
コード例 #13
0
ファイル: roots.hpp プロジェクト: 3DJ/ofxOgre
T newton_raphson_iterate(F f, T guess, T min, T max, int digits, boost::uintmax_t& max_iter)
{
   BOOST_MATH_STD_USING

   T f0(0), f1, last_f0(0);
   T result = guess;

   T factor = static_cast<T>(ldexp(1.0, 1 - digits));
   T delta = 1;
   T delta1 = tools::max_value<T>();
   T delta2 = tools::max_value<T>();

   boost::uintmax_t count(max_iter);

   do{
      last_f0 = f0;
      delta2 = delta1;
      delta1 = delta;
      boost::math::tie(f0, f1) = f(result);
      if(0 == f0)
         break;
      if(f1 == 0)
      {
         // Oops zero derivative!!!
#ifdef BOOST_MATH_INSTRUMENT
         std::cout << "Newton iteration, zero derivative found" << std::endl;
#endif
         detail::handle_zero_derivative(f, last_f0, f0, delta, result, guess, min, max);
      }
      else
      {
         delta = f0 / f1;
      }
#ifdef BOOST_MATH_INSTRUMENT
      std::cout << "Newton iteration, delta = " << delta << std::endl;
#endif
      if(fabs(delta * 2) > fabs(delta2))
      {
         // last two steps haven't converged, try bisection:
         delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
      }
      guess = result;
      result -= delta;
      if(result <= min)
      {
         delta = 0.5F * (guess - min);
         result = guess - delta;
         if((result == min) || (result == max))
            break;
      }
      else if(result >= max)
      {
         delta = 0.5F * (guess - max);
         result = guess - delta;
         if((result == min) || (result == max))
            break;
      }
      // update brackets:
      if(delta > 0)
         max = guess;
      else
         min = guess;
   }while(--count && (fabs(result * factor) < fabs(delta)));

   max_iter -= count;

#ifdef BOOST_MATH_INSTRUMENT
   std::cout << "Newton Raphson iteration, final count = " << max_iter << std::endl;

   static boost::uintmax_t max_count = 0;
   if(max_iter > max_count)
   {
      max_count = max_iter;
      std::cout << "Maximum iterations: " << max_iter << std::endl;
   }
#endif

   return result;
}
コード例 #14
0
ファイル: number.o.c プロジェクト: hoobaa/mecl
cl_object
cl_rational(cl_object x)
{
	double d;
 AGAIN:
	switch (ecl_t_of(x)) {
	case t_fixnum:
	case t_bignum:
	case t_ratio:
		break;
	case t_singlefloat:
		d = ecl_single_float(x);
		goto GO_ON;
	case t_doublefloat:
		d = ecl_double_float(x);
	GO_ON:	if (d == 0) {
			x = ecl_make_fixnum(0);
		} else {
			int e;
			d = frexp(d, &e);
			e -= DBL_MANT_DIG;
			x = _ecl_double_to_integer(ldexp(d, DBL_MANT_DIG));
                        if (e != 0) {
                                x = ecl_times(ecl_expt(ecl_make_fixnum(FLT_RADIX),
                                                       ecl_make_fixnum(e)),
                                              x);
                        }
		}
		break;
#ifdef ECL_LONG_FLOAT
	case t_longfloat: {
		long double d = ecl_long_float(x);
		if (d == 0) {
			x = ecl_make_fixnum(0);
		} else {
			int e;
			d = frexpl(d, &e);
			e -= LDBL_MANT_DIG;
                        d = ldexpl(d, LDBL_MANT_DIG);
			x = _ecl_long_double_to_integer(d);
			if (e != 0) {
				x = ecl_times(ecl_expt(ecl_make_fixnum(FLT_RADIX),
                                                       ecl_make_fixnum(e)),
                                              x);
			}
		}
		break;
	}
#endif
	default:
		x = ecl_type_error(ECL_SYM("RATIONAL",687),"argument",x,ECL_SYM("NUMBER",606));
		goto AGAIN;
	}
	{
#line 871
		const cl_env_ptr the_env = ecl_process_env();
#line 871
		#line 871
		cl_object __value0 = x;
#line 871
		the_env->nvalues = 1;
#line 871
		return __value0;
#line 871
	}

}
コード例 #15
0
ファイル: output.c プロジェクト: aspt/diff_tools
/**
*   Comparison report (short or long)
*/
void OUTPUT_print_file_stat (wav_file_t * wf[2], file_stat_t * diff, cmdline_options_t * opt)
{
    unsigned int i;
    double  dblPCMscale;
    static TCHAR s[4096];
    TCHAR *  p;
    double absmax_scaled;

    channel_stat_t * tot = diff->ch + diff->nch;
    channel_stat_t * ch = diff->ch;
    unsigned int nch = diff->nch;
    double n_samples = (double)diff->samlpes_count;
    double tot_samples = nch * n_samples;
    int have_offset = OffsetInfoHaveOffset(diff, opt);

    int stat_bips = MIN(labs(wf[0]->fmt.bips), labs(wf[1]->fmt.bips));
    if (wf[0]->fmt.pcm_type == E_PCM_IEEE_FLOAT)
    {
        stat_bips = wf[1]->fmt.pcm_type == E_PCM_IEEE_FLOAT ? 16 : labs(wf[1]->fmt.bips);
    }
    if (wf[1]->fmt.pcm_type == E_PCM_IEEE_FLOAT)
    {
        stat_bips = wf[0]->fmt.pcm_type == E_PCM_IEEE_FLOAT ? 16 : labs(wf[0]->fmt.bips);
    }
    dblPCMscale = ldexp(1, stat_bips - 1);
    if (opt->listing == E_LISTING_SHORT || (opt->listing == E_LISTING_NO_BITEXACT && (tot->d_sumSqr != 0 || have_offset)))
    {
        ptrdiff_t anchors[ANCHORS_COUNT];
        p = s;
        p += _stprintf(p, _T("PSNR (dB):%-9.9s"), DB(tot->d_sumSqr, tot_samples));

#if 0
        // use minimum BIPS of comparing files
        p += _stprintf(p, _T("Max*2^%2d:(%.0f"), stat_bips, diff_stat_abs_max(ch + 0) * dblPCMscale);
        for (i = 1; i < nch; i++)
        {
            p += _stprintf(p, _T(" : %.0f"), diff_stat_abs_max(ch + i) * dblPCMscale);
        }
        p += _stprintf(p, _T(")"));
#else
        // always use 16-bit BIPS
        absmax_scaled = diff_stat_abs_max(diff->ch + 0) * (1<<15);
        p += _stprintf(p, _T("Max*2^16:(%s"), print_float(absmax_scaled, 9, (absmax_scaled != 0 && absmax_scaled < 1)?2:0));
        for (i = 1; i < nch; i++)
        {
            absmax_scaled = diff_stat_abs_max(diff->ch + i) * (1<<15);
            p += _stprintf(p, _T(" : %s"), print_float(absmax_scaled, 9, (absmax_scaled != 0 && absmax_scaled < 1)?2:0));
        }
        p += _stprintf(p, _T(")"));
#endif
#define FIX_ANCHORS(z) for (anchors[z] = p - s; anchors[z] < g_anchors[z]; anchors[z]++) *p++ = ' ';

        while (p - s < 40 || (p - s) % 8)
        {
            *p++ = ' ';
        }
        FIX_ANCHORS(0)

        if (wf[0]->container != wf[1]->container)
        {
            p += _stprintf(p, _T(" %s<->%s/"), WAV_format_string(wf[0]), WAV_format_string(wf[1]));
        }
        else
        {
            p += _stprintf(p, _T(" %s/"), WAV_format_string(wf[0]));
        }
        FIX_ANCHORS(1)

        if (wf[0]->fmt.bips != wf[1]->fmt.bips || wf[0]->fmt.pcm_type != wf[1]->fmt.pcm_type)
        {
            p += print_bips_short(p, wf[0]);
            p += _stprintf(p, _T("<->"));
            p += print_bips_short(p, wf[1]);
        }
        else
        {
            p += print_bips_short(p, wf[0]);
        }
        FIX_ANCHORS(2)

        if (wf[0]->fmt.hz != wf[1]->fmt.hz && wf[0]->fmt.hz != 0 && wf[1]->fmt.hz != 0)
        {
            p += _stprintf(p, _T("/%5lu<->%5lu "), wf[0]->fmt.hz, wf[1]->fmt.hz);
        }
        else
        {
            p += _stprintf(p, _T("/%5lu "), wf[0]->fmt.hz ? wf[0]->fmt.hz : wf[1]->fmt.hz);
        }
        FIX_ANCHORS(3)

        p += _stprintf(p, _T("[%7u smp] "), diff->samlpes_count);

        FIX_ANCHORS(4)

        if (have_offset)
        {
            p += _stprintf(p, _T(" Offsets: "));
            if (opt->offset_bytes[0])
            {
                p += _stprintf(p, _T("%u bytes + "), opt->offset_bytes[0]);
            }
            if (diff->actualOffsetSamples[0])
            {
                p += _stprintf(p, _T("%lu+"), diff->actualOffsetSamples[0]);
            }
            p += _stprintf(p, _T("[1st]"));
            if (diff->remainingSamples[0])
            {
                p += _stprintf(p, _T("+%") _T(PRIi64), diff->remainingSamples[0]);
            }
            FIX_ANCHORS(5)
            p += _stprintf(p, _T(" <-> "));
            if (opt->offset_bytes[1])
            {
                p += _stprintf(p, _T("%u bytes + "), opt->offset_bytes[1]);
            }
            if (diff->actualOffsetSamples[1])
            {
                p += _stprintf(p, _T("%u+"), diff->actualOffsetSamples[1]);
            }
            p += _stprintf(p, _T("[2nd]"));
            if (diff->remainingSamples[1])
            {
                p += _stprintf(p, _T("+%") _T(PRIi64), diff->remainingSamples[1]);
            }
        }
        else
        {
            FIX_ANCHORS(5)
        }
        
        while ((p - s) % 16)
        {
            *p++ = ' ';
        } 
        FIX_ANCHORS(6)

        p += _stprintf(p, _T(" %s"), PATH_after_last_separator(opt->file_name[0]));
        if (_tcscmp(
                 PATH_after_last_separator(opt->file_name[0]), 
                 PATH_after_last_separator(opt->file_name[1])
                 ))
        {
            while ((p - s) % 16)
            {
                *p++ = ' ';
            } 
            FIX_ANCHORS(7)

            p += _stprintf(p, _T(" <-> "));
            p += _stprintf(p, _T(" %s"), PATH_after_last_separator(opt->file_name[1]));
        }
        else
        {
            FIX_ANCHORS(7)
        }

        *p++ = '\n';
        *p++ = '\0';
        FIX_ANCHORS(8)
        anchors_save_line(anchors, s);
        my_puts(s);
    }
コード例 #16
0
ファイル: testlx.c プロジェクト: yduh/yukawa_study
int main(void)
{
   int k,test1,test2;
   int *state1,*state2;
   float sbase;
   float xs[NXS],ys[NXS],xsn[96];
   double base;
   double xd[NXD],yd[NXD],xdn[48];

   sbase=(float)(ldexp(1.0,24));
   base=ldexp(1.0,48);
   state1=malloc(rlxs_size()*sizeof(int));
   state2=malloc(rlxd_size()*sizeof(int));
   
   rlxs_init(0,32767);
   rlxd_init(1,32767);


/*******************************************************************************
*
* Check that the correct sequences of random numbers are obtained
*
*******************************************************************************/

   for (k=0;k<20;k++)
   {
      ranlxs(xs,NXS);
      ranlxd(xd,NXD);
   }

   xsn[0]=13257445.0f;
   xsn[1]=15738482.0f;
   xsn[2]=5448599.0f;
   xsn[3]=9610459.0f;
   xsn[4]=1046025.0f;
   xsn[5]=2811360.0f;
   xsn[6]=14923726.0f;
   xsn[7]=2287739.0f;
   xsn[8]=16133204.0f;
   xsn[9]=16328320.0f;
   xsn[10]=12980218.0f;
   xsn[11]=9256959.0f;
   xsn[12]=5633754.0f;
   xsn[13]=7422961.0f;
   xsn[14]=6032411.0f;
   xsn[15]=14970828.0f;
   xsn[16]=10717272.0f;
   xsn[17]=2520878.0f;
   xsn[18]=8906135.0f;
   xsn[19]=8507426.0f;
   xsn[20]=11925022.0f;
   xsn[21]=12042827.0f;
   xsn[22]=12263021.0f;
   xsn[23]=4828801.0f;
   xsn[24]=5300508.0f;
   xsn[25]=13346776.0f;
   xsn[26]=10869790.0f;
   xsn[27]=8520207.0f;
   xsn[28]=11213953.0f;
   xsn[29]=14439320.0f;
   xsn[30]=5716476.0f;
   xsn[31]=13600448.0f;
   xsn[32]=12545579.0f;
   xsn[33]=3466523.0f;
   xsn[34]=113906.0f;
   xsn[35]=10407879.0f;
   xsn[36]=12058596.0f;
   xsn[37]=4390921.0f;
   xsn[38]=1634350.0f;
   xsn[39]=9823280.0f;
   xsn[40]=12569690.0f;
   xsn[41]=8267856.0f;
   xsn[42]=5869501.0f;
   xsn[43]=7210219.0f;
   xsn[44]=1362361.0f;
   xsn[45]=2956909.0f;
   xsn[46]=504465.0f;
   xsn[47]=6664636.0f;
   xsn[48]=6048963.0f;
   xsn[49]=1098525.0f;
   xsn[50]=1261330.0f;
   xsn[51]=2401071.0f;
   xsn[52]=8087317.0f;
   xsn[53]=1293933.0f;
   xsn[54]=555494.0f;
   xsn[55]=14872475.0f;
   xsn[56]=11261534.0f;
   xsn[57]=166813.0f;
   xsn[58]=13424516.0f;
   xsn[59]=15280818.0f;
   xsn[60]=4644497.0f;
   xsn[61]=6333595.0f;
   xsn[62]=10012569.0f;
   xsn[63]=6878028.0f;
   xsn[64]=9176136.0f;
   xsn[65]=8379433.0f;
   xsn[66]=11073957.0f;
   xsn[67]=2465529.0f;
   xsn[68]=13633550.0f;
   xsn[69]=12721649.0f;
   xsn[70]=569725.0f;
   xsn[71]=6375015.0f;
   xsn[72]=2164250.0f;
   xsn[73]=6725885.0f;
   xsn[74]=7223108.0f;
   xsn[75]=4890858.0f;
   xsn[76]=11298261.0f;
   xsn[77]=12086020.0f;
   xsn[78]=4447706.0f;
   xsn[79]=1164782.0f;
   xsn[80]=1904399.0f;
   xsn[81]=16669839.0f;
   xsn[82]=2586766.0f;
   xsn[83]=3605708.0f;
   xsn[84]=15761082.0f;
   xsn[85]=14937769.0f;
   xsn[86]=13965017.0f;
   xsn[87]=2175021.0f;
   xsn[88]=16668997.0f;
   xsn[89]=13996602.0f;
   xsn[90]=6313099.0f;
   xsn[91]=15646036.0f;
   xsn[92]=9746447.0f;
   xsn[93]=9596781.0f;
   xsn[94]=9244169.0f;
   xsn[95]=4731726.0f;

   xdn[0]=135665102723086.0;
   xdn[1]=259840970195871.0;
   xdn[2]=110726726657103.0;
   xdn[3]=53972500363809.0;
   xdn[4]=199301297412157.0;
   xdn[5]=63744794353870.0;
   xdn[6]=178745978725904.0;
   xdn[7]=243549380863176.0;
   xdn[8]=244796821836177.0;
   xdn[9]=223788809121855.0;
   xdn[10]=113720856430443.0;
   xdn[11]=124607822268499.0;
   xdn[12]=25705458431399.0;
   xdn[13]=155476863764950.0;
   xdn[14]=195602097736933.0;
   xdn[15]=183038707238950.0;
   xdn[16]=62268883953527.0;
   xdn[17]=157047615112119.0;
   xdn[18]=58134973897037.0;
   xdn[19]=26908869337679.0;
   xdn[20]=259927185454290.0;
   xdn[21]=130534606773507.0;
   xdn[22]=205295065526788.0;
   xdn[23]=40201323262686.0;
   xdn[24]=193822255723177.0;
   xdn[25]=239720285097881.0;
   xdn[26]=54433631586673.0;
   xdn[27]=31313178820772.0;
   xdn[28]=152904879618865.0;
   xdn[29]=256187025780734.0;
   xdn[30]=110292144635528.0;
   xdn[31]=26555117184469.0;
   xdn[32]=228913371644996.0;
   xdn[33]=126837665590799.0;
   xdn[34]=141069100232139.0;
   xdn[35]=96171028602910.0;
   xdn[36]=259271018918511.0;
   xdn[37]=65257892816619.0;
   xdn[38]=14254344610711.0;
   xdn[39]=137794868158301.0;
   xdn[40]=269703238916504.0;
   xdn[41]=35782602710520.0;
   xdn[42]=51447305327263.0;
   xdn[43]=247852246697199.0;
   xdn[44]=65072958134912.0;
   xdn[45]=273325640150591.0;
   xdn[46]=2768714666444.0;
   xdn[47]=173907458721736.0;
   
   test1=0;
   test2=0;

   for (k=0;k<96;k++)
   {
      if (xsn[k]!=(xs[k+60]*sbase))
         test1=1;
   }

   for (k=0;k<48;k++)
   {
      if (xdn[k]!=(xd[k+39]*base))
         test2=1;
   }

   if (test1==1)
   {
      printf("\n");
      printf("Test failed: ranlxs gives incorrect results\n");
      printf("=> do not use ranlxs on this machine\n");
      printf("\n");
   }

   if (test2==1)
   {
      printf("\n");
      printf("Test failed: ranlxd gives incorrect results\n");
      printf("=> do not use ranlxd on this machine\n");
      printf("\n");
   }


/*******************************************************************************
*
* Check of the I/O routines
*
*******************************************************************************/

   rlxs_get(state1);
   rlxd_get(state2);

   for (k=0;k<10;k++)
   {
      ranlxs(xs,NXS);
      ranlxd(xd,NXD);
   }

   rlxs_reset(state1);
   rlxd_reset(state2);

   for (k=0;k<10;k++)
   {
      ranlxs(ys,NXS);
      ranlxd(yd,NXD);
   }

   for (k=0;k<NXS;k++)
   {
      if (xs[k]!=ys[k])
         test1=2;
   }

   for (k=0;k<NXD;k++)
   {
      if (xd[k]!=yd[k])
         test2=2;
   }

   if (test1==2)
   {
      printf("\n");
      printf("Test failed: I/O routines for ranlxs do not work properly\n");
      printf("=> do not use ranlxs on this machine\n");
      printf("\n");
   }

   if (test2==2)
   {
      printf("\n");
      printf("Test failed: I/O routines for ranlxd do not work properly\n");
      printf("=> do not use ranlxd on this machine\n");
      printf("\n");
   }


/*******************************************************************************
*
* Success messages
*
*******************************************************************************/

   if ((test1==0)&&(test2==0))
   {
      printf("\n");
      printf("All tests passed\n");
      printf("=> ranlxs and ranlxd work correctly on this machine\n");
      printf("\n");
   }
   else if (test1==0)
   {
      printf("\n");
      printf("All tests on ranlxs passed\n");
      printf("=> ranlxs works correctly on this machine\n");
      printf("\n");
   }
   else if (test2==0)
   {
      printf("\n");
      printf("All tests on ranlxd passed\n");
      printf("=> ranlxd works correctly on this machine\n");
      printf("\n");
   }
   exit(0);
}
コード例 #17
0
ファイル: trig.c プロジェクト: Ayato-Harashima/CMVS-PMVS
int
gsl_sf_cos_e(double x, gsl_sf_result * result)
{
  /* CHECK_POINTER(result) */

  {
    const double P1 = 7.85398125648498535156e-1;
    const double P2 = 3.77489470793079817668e-8;
    const double P3 = 2.69515142907905952645e-15;

    const double abs_x = fabs(x);

    if(abs_x < GSL_ROOT4_DBL_EPSILON) {
      const double x2 = x*x;
      result->val = 1.0 - 0.5*x2;
      result->err = fabs(x2*x2/12.0);
      return GSL_SUCCESS;
    }
    else {
      double sgn_result = 1.0;
      double y = floor(abs_x/(0.25*M_PI));
      int octant = y - ldexp(floor(ldexp(y,-3)),3);
      int stat_cs;
      double z;

      if(GSL_IS_ODD(octant)) {
        octant += 1;
        octant &= 07;
        y += 1.0;
      }

      if(octant > 3) {
        octant -= 4;
        sgn_result = -sgn_result;
      }

      if(octant > 1) {
        sgn_result = -sgn_result;
      }

      z = ((abs_x - y * P1) - y * P2) - y * P3;

      if(octant == 0) {
        gsl_sf_result cos_cs_result;
        const double t = 8.0*fabs(z)/M_PI - 1.0;
        stat_cs = cheb_eval_e(&cos_cs, t, &cos_cs_result);
        result->val = 1.0 - 0.5*z*z * (1.0 - z*z * cos_cs_result.val);
      }
      else { /* octant == 2 */
        gsl_sf_result sin_cs_result;
        const double t = 8.0*fabs(z)/M_PI - 1.0;
        stat_cs = cheb_eval_e(&sin_cs, t, &sin_cs_result);
        result->val = z * (1.0 + z*z * sin_cs_result.val);
      }

      result->val *= sgn_result;

      if(abs_x > 1.0/GSL_DBL_EPSILON) {
        result->err = fabs(result->val);
      }
      else if(abs_x > 100.0/GSL_SQRT_DBL_EPSILON) {
        result->err = 2.0 * abs_x * GSL_DBL_EPSILON * fabs(result->val);
      }
      else if(abs_x > 0.1/GSL_SQRT_DBL_EPSILON) {
        result->err = 2.0 * GSL_SQRT_DBL_EPSILON * fabs(result->val);
      }
      else {
        result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
      }

      return stat_cs;
    }
  }
}
コード例 #18
0
double
attribute_hidden
ldexpl (double x, int exponent)
{
  return ldexp (x, exponent);
}
コード例 #19
0
ファイル: stubs.c プロジェクト: Fokycnuk/gcc
long double
ldexpl(long double x, int exp)
{
  return ldexp((double) x, exp);
}
コード例 #20
0
float ldexpf (float x, int _exp)
{
	return (float) ldexp( (double)x, _exp );
}
コード例 #21
0
static void
F(compile_test) (void)
{
  TYPE a, b, c = 1.0;
  complex TYPE d;
  int i;
  int saved_count;
  long int j;
  long long int k;

  a = cos (cos (x));
  b = acos (acos (a));
  a = sin (sin (x));
  b = asin (asin (a));
  a = tan (tan (x));
  b = atan (atan (a));
  c = atan2 (atan2 (a, c), atan2 (b, x));
  a = cosh (cosh (x));
  b = acosh (acosh (a));
  a = sinh (sinh (x));
  b = asinh (asinh (a));
  a = tanh (tanh (x));
  b = atanh (atanh (a));
  a = exp (exp (x));
  b = log (log (a));
  a = log10 (log10 (x));
  b = ldexp (ldexp (a, 1), 5);
  a = frexp (frexp (x, &i), &i);
  b = expm1 (expm1 (a));
  a = log1p (log1p (x));
  b = logb (logb (a));
  a = exp2 (exp2 (x));
  b = log2 (log2 (a));
  a = pow (pow (x, a), pow (c, b));
  b = sqrt (sqrt (a));
  a = hypot (hypot (x, b), hypot (c, a));
  b = cbrt (cbrt (a));
  a = ceil (ceil (x));
  b = fabs (fabs (a));
  a = floor (floor (x));
  b = fmod (fmod (a, b), fmod (c, x));
  a = nearbyint (nearbyint (x));
  b = round (round (a));
  a = trunc (trunc (x));
  b = remquo (remquo (a, b, &i), remquo (c, x, &i), &i);
  j = lrint (x) + lround (a);
  k = llrint (b) + llround (c);
  a = erf (erf (x));
  b = erfc (erfc (a));
  a = tgamma (tgamma (x));
  b = lgamma (lgamma (a));
  a = rint (rint (x));
  b = nextafter (nextafter (a, b), nextafter (c, x));
  a = nextdown (nextdown (a));
  b = nexttoward (nexttoward (x, a), c);
  a = nextup (nextup (a));
  b = remainder (remainder (a, b), remainder (c, x));
  a = scalb (scalb (x, a), (TYPE) (6));
  k = scalbn (a, 7) + scalbln (c, 10l);
  i = ilogb (x);
  j = llogb (x);
  a = fdim (fdim (x, a), fdim (c, b));
  b = fmax (fmax (a, x), fmax (c, b));
  a = fmin (fmin (x, a), fmin (c, b));
  b = fma (sin (a), sin (x), sin (c));
  a = totalorder (totalorder (x, b), totalorder (c, x));
  b = totalordermag (totalordermag (x, a), totalordermag (c, x));

#ifdef TEST_INT
  a = atan2 (i, b);
  b = remquo (i, a, &i);
  c = fma (i, b, i);
  a = pow (i, c);
#endif
  x = a + b + c + i + j + k;

  saved_count = count;
  if (ccount != 0)
    ccount = -10000;

  d = cos (cos (z));
  z = acos (acos (d));
  d = sin (sin (z));
  z = asin (asin (d));
  d = tan (tan (z));
  z = atan (atan (d));
  d = cosh (cosh (z));
  z = acosh (acosh (d));
  d = sinh (sinh (z));
  z = asinh (asinh (d));
  d = tanh (tanh (z));
  z = atanh (atanh (d));
  d = exp (exp (z));
  z = log (log (d));
  d = sqrt (sqrt (z));
  z = conj (conj (d));
  d = fabs (conj (a));
  z = pow (pow (a, d), pow (b, z));
  d = cproj (cproj (z));
  z += fabs (cproj (a));
  a = carg (carg (z));
  b = creal (creal (d));
  c = cimag (cimag (z));
  x += a + b + c + i + j + k;
  z += d;

  if (saved_count != count)
    count = -10000;

  if (0)
    {
      a = cos (y);
      a = acos (y);
      a = sin (y);
      a = asin (y);
      a = tan (y);
      a = atan (y);
      a = atan2 (y, y);
      a = cosh (y);
      a = acosh (y);
      a = sinh (y);
      a = asinh (y);
      a = tanh (y);
      a = atanh (y);
      a = exp (y);
      a = log (y);
      a = log10 (y);
      a = ldexp (y, 5);
      a = frexp (y, &i);
      a = expm1 (y);
      a = log1p (y);
      a = logb (y);
      a = exp2 (y);
      a = log2 (y);
      a = pow (y, y);
      a = sqrt (y);
      a = hypot (y, y);
      a = cbrt (y);
      a = ceil (y);
      a = fabs (y);
      a = floor (y);
      a = fmod (y, y);
      a = nearbyint (y);
      a = round (y);
      a = trunc (y);
      a = remquo (y, y, &i);
      j = lrint (y) + lround (y);
      k = llrint (y) + llround (y);
      a = erf (y);
      a = erfc (y);
      a = tgamma (y);
      a = lgamma (y);
      a = rint (y);
      a = nextafter (y, y);
      a = nexttoward (y, y);
      a = remainder (y, y);
      a = scalb (y, (const TYPE) (6));
      k = scalbn (y, 7) + scalbln (y, 10l);
      i = ilogb (y);
      j = llogb (y);
      a = fdim (y, y);
      a = fmax (y, y);
      a = fmin (y, y);
      a = fma (y, y, y);
      a = totalorder (y, y);
      a = totalordermag (y, y);

#ifdef TEST_INT
      a = atan2 (i, y);
      a = remquo (i, y, &i);
      a = fma (i, y, i);
      a = pow (i, y);
#endif

      d = cos ((const complex TYPE) z);
      d = acos ((const complex TYPE) z);
      d = sin ((const complex TYPE) z);
      d = asin ((const complex TYPE) z);
      d = tan ((const complex TYPE) z);
      d = atan ((const complex TYPE) z);
      d = cosh ((const complex TYPE) z);
      d = acosh ((const complex TYPE) z);
      d = sinh ((const complex TYPE) z);
      d = asinh ((const complex TYPE) z);
      d = tanh ((const complex TYPE) z);
      d = atanh ((const complex TYPE) z);
      d = exp ((const complex TYPE) z);
      d = log ((const complex TYPE) z);
      d = sqrt ((const complex TYPE) z);
      d = pow ((const complex TYPE) z, (const complex TYPE) z);
      d = fabs ((const complex TYPE) z);
      d = carg ((const complex TYPE) z);
      d = creal ((const complex TYPE) z);
      d = cimag ((const complex TYPE) z);
      d = conj ((const complex TYPE) z);
      d = cproj ((const complex TYPE) z);
    }
}
コード例 #22
0
ファイル: t-double.c プロジェクト: AllardJ/Tomato
void
testmain (int argc, char **argv)
{
  unsigned i;
  mpz_t x;

  for (i = 0; values[i].s; i++)
    {
      char *s;
      mpz_init_set_d (x, values[i].d);
      s = mpz_get_str (NULL, 16, x);
      if (strcmp (s, values[i].s) != 0)
	{
	  fprintf (stderr, "mpz_set_d failed:\n"
		   "d = %.20g\n"
		   "s = %s\n"
		   "r = %s\n",
		   values[i].d, s, values[i].s);
	  abort ();
	}
      testfree (s);
      mpz_clear (x);
    }

  mpz_init (x);

  for (i = 0; i < COUNT; i++)
    {
      /* Use volatile, to avoid extended precision in floating point
	 registers, e.g., on m68k and 80387. */
      volatile double d, f;
      unsigned long m;
      int e;

      mini_rrandomb (x, GMP_LIMB_BITS);
      m = mpz_get_ui (x);
      mini_urandomb (x, 8);
      e = mpz_get_ui (x) - 100;

      d = ldexp ((double) m, e);
      mpz_set_d (x, d);
      f = mpz_get_d (x);
      if (f != floor (d))
	{
	  fprintf (stderr, "mpz_set_d/mpz_get_d failed:\n");
	  goto dumperror;
	}
      if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) >= 0))
	{
	  fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
	  goto dumperror;
	}
      f = d + 1.0;
      if (f > d && ! (mpz_cmp_d (x, f) < 0))
	{
	  fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");
	  goto dumperror;
	}

      d = - d;

      mpz_set_d (x, d);
      f = mpz_get_d (x);
      if (f != ceil (d))
	{
	  fprintf (stderr, "mpz_set_d/mpz_get_d failed:\n");
	dumperror:
	  dump ("x", x);
	  fprintf (stderr, "m = %lx, e = %i\n", m, e);
	  fprintf (stderr, "d = %.15g\n", d);
	  fprintf (stderr, "f = %.15g\n", f);
	  fprintf (stderr, "f - d = %.5g\n", f - d);
	  abort ();
	}
      if ((f == d) ? (mpz_cmp_d (x, d) != 0) : (mpz_cmp_d (x, d) <= 0))
	{
	  fprintf (stderr, "mpz_cmp_d (x, d) failed:\n");
	  goto dumperror;
	}
      f = d - 1.0;
      if (f < d && ! (mpz_cmp_d (x, f) > 0))
	{
	  fprintf (stderr, "mpz_cmp_d (x, f) failed:\n");
	  goto dumperror;
	}
    }

  mpz_clear (x);
}
コード例 #23
0
ファイル: opnormt.c プロジェクト: jjgreen/opnorm
static void* worker(tdat_t *td)
{

#ifdef HAVE_SIGNAL_H

  /* set this thread as cancellable */

  if (set_cancellable() != 0)
    {
      td->status = OPNORM_THREAD;
      return NULL;
    }

#endif

  /*
    unpack arguments, mostly for readability but also saves
    a few dereferences
  */

  tdat_shared_t *ts = td->shared;

  index_t
    n = ts->n,
    m = ts->m;

  double
    p    = ts->p,
    q    = ts->q,
    eps  = ts->eps,
    LCRP = ts->LCRP,
    SCD  = ts->SCD;

  const double *M = ts->M;

  fifo_t *fifo = ts->fifo;

  /* working data */

  double  pcent[n];
  cube_t  cube0, cube1;
  patch_t patch;
  double  tmax = 0.0;

  patch.centres = pcent;

  int fifoerr;

  while (1)
    {
      /* thread cancellation point  */

      pthread_testcancel();

      /* dequeue a cube */

      if (pthread_mutex_lock(&(ts->fifolock)) < 0)
	{
	  td->status = OPNORM_THREAD;
	  return NULL;
	}

      fifoerr = fifo_dequeue(fifo, &cube0);

      if (pthread_mutex_unlock(&(ts->fifolock)) < 0)
	{
	  td->status = OPNORM_THREAD;
	  return NULL;
	}

      if (fifoerr != FIFO_OK)
	{
	  td->status = (fifoerr == FIFO_EMPTY ?
			OPNORM_OK :
			OPNORM_FIFO);
	  return NULL;
	}

      cube_print(&cube0, n, ">");

      /* nfifo is the total number dequeue */

      td->nfifo++;

      /* cube subdivide */

      int hwnexp = cube0.hwnexp + 1;
      double halfwidth = ldexp(1, -hwnexp);

      /*
	if halfwidth < DBL_EPSILON then we cannot
	calulate the centres of the subdivided cubes
	accurately, we break out and report that the
	requested accuracy could not be achieved
      */

      if (halfwidth < DBL_EPSILON)
	{
	  td->status = OPNORM_INACC;
	  return NULL;
	}

      for (size_t k = 0 ; k < (1UL << (n-1)) ; k++)
	{
	  cube1.side = cube0.side;
	  cube1.hwnexp = hwnexp;

	  /*
	    we give our cube1 a temporary set of centres
	    while we evaluate and decide whether to jetison
	    or enqueue it, only if the latter do we make a
	    malloc and copy the temporary centres.  this
	    saves a *lot* of malloc/free pairs
	  */

	  double centres[n];
	  cube1.centres = centres;

	  size_t k0 = k;

	  for (size_t j = 0 ; j < n ; j++)
	    {
	      if (cube0.side == j)
		{
		  cube1.centres[j] = cube0.centres[j];
		  continue;
		}

	      cube1.centres[j] = cube0.centres[j] +
		((k0 % 2) ? halfwidth : -halfwidth);

	      k0 /= 2;
	    }

	  cube_print(&cube1, n, "<");

	  /* get the corresponding patch */

	  cube_to_patch(&cube1, n, p, LCRP, SCD, &patch);
	  patch_print(patch, n);

	  double ratio = radius_to_ratio(patch.radius, p);

	  /*
	    check for patch viability - this check almost
	    always succeeds (on Drury K, this is false in
	    80/164016 cases, so 0.05% of the time) very
	    small beer. Yet it introduces a branch point,
	    so one might think it worth removing. Timing
	    tests indicate that there is no speedup in
	    doing so, so we keep it.
	  */

	  if (ratio > 0)
	    {
	      /* evaluate M at patch centre */

	      double v[m];

	      ts->matvec(M, pcent, m, n, v);
	      td->neval++;

	      double t = pnorm(v, m, q);

	      /* test first with the previous value of tmax */

	      if (t < tmax)
		{
		  /* test whether we can jettison this cube */

		  if (t < (tmax * ratio * (1 + eps))) continue;

		  /*
		    note that the global ts->tmax >= tmax so it would
		    be pointless (and cost a mutex access) to test
		    for that here
		  */
		}
	      else
		{
		  if (pthread_mutex_lock(&(ts->maxlock)) < 0)
		    {
		      td->status = OPNORM_THREAD;
		      return NULL;
		    }

		  /* update local tmax from global */

		  tmax = ts->tmax;

		  /*
		    if we have found a new global maximum then we
		    update it (and the global maximising vector)
		    as well as the local copy
		  */

		  if (t > tmax)
		    {
		      ts->tmax = tmax = t;

		      if (ts->vmax)
			memcpy(ts->vmax, pcent, n*sizeof(double));
		    }

		  if (pthread_mutex_unlock(&(ts->maxlock)) < 0)
		    {
		      td->status = OPNORM_THREAD;
		      return NULL;
		    }

		  /*
		    test whether we can jettison this cube but
		    now with the updated value of tmax
		  */

		  if (t < (tmax * ratio * (1 + eps))) continue;

		}
	    }

	  /*
	    we will enqueue this cube, so we need to
	    allocate and copy its temporary centres set
	  */

	  if (! (cube1.centres = malloc(n*sizeof(double))))
	    {
	      td->status = OPNORM_ALLOC;
	      return NULL;
	    }

	  memcpy(cube1.centres, centres, n*sizeof(double));

	  if (pthread_mutex_lock(&(ts->fifolock)) < 0)
	    {
	      free(cube1.centres);
	      td->status = OPNORM_THREAD;
	      return NULL;
	    }

	  fifoerr = fifo_enqueue(fifo, &cube1);

	  if (pthread_mutex_unlock(&(ts->fifolock)) < 0)
	    {
	      td->status = OPNORM_THREAD;
	      return NULL;
	    }

	  switch(fifoerr)
	    {
	    case FIFO_OK:
	      break;
	    case FIFO_USERMAX:
	      td->status = OPNORM_FIFOMAX;
	      return NULL;
	    default:
	      td->status = OPNORM_FIFO;
	      return NULL;
	    }
	}

      free(cube0.centres);
    }

  /* we should not arrive here */

  td->status = OPNORM_BUG;

  return NULL;
}
コード例 #24
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("d_log_upper_bound....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        mpfr_t t;
        double x, y, z;

        mpfr_init2(t, 53);

        x = d_randtest2(state);
        x = ldexp(x, 100 - n_randint(state, 200));

        switch (n_randint(state, 10))
        {
            case 0:
                x = 1.0 + x;
                break;
            case 1:
                x = 1.0 - x;
                break;
            case 2:
                x = D_INF;
                break;
            case 3:
                x = 0.0;
                break;
            case 4:
                x = D_NAN;
                break;
            default:
                break;
        }

        y = mag_d_log_upper_bound(x);

        mpfr_set_d(t, x, MPFR_RNDD);
        mpfr_log(t, t, MPFR_RNDU);
        z = mpfr_get_d(t, MPFR_RNDD);

        if (y < z || fabs(y-z) > 0.000001 * fabs(z))
        {
            flint_printf("FAIL\n");
            flint_printf("x = %.20g\n", x);
            flint_printf("y = %.20g\n", y);
            flint_printf("z = %.20g\n", z);
            flint_abort();
        }

        mpfr_clear(t);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
コード例 #25
0
ファイル: warble.c プロジェクト: UMadeIt/rockbox-cygwin
static uint64_t make_float64(int32_t sample, int shift)
{
    /* TODO: be more portable */
    double val = ldexp(sample, -shift);
    return *(uint64_t*)&val;
}
コード例 #26
0
ファイル: math.c プロジェクト: robbiemc/joule
static u32 lua_math_ldexp(LSTATE) {
  lstate_return1(lv_number(ldexp(lstate_getnumber(0),
                                 (int) lstate_getnumber(1))));
}
コード例 #27
0
ファイル: test_bessel_k.hpp プロジェクト: LancelotGHX/Simula
void test_bessel(T, const char* name)
{
    // function values calculated on http://functions.wolfram.com/
    static const boost::array<boost::array<T, 3>, 9> k0_data = {{
        {{ SC_(0.0), SC_(1.0), SC_(0.421024438240708333335627379212609036136219748226660472298970) }},
        {{ SC_(0.0), SC_(2.0), SC_(0.113893872749533435652719574932481832998326624388808882892530) }},
        {{ SC_(0.0), SC_(4.0), SC_(0.0111596760858530242697451959798334892250090238884743405382553) }},
        {{ SC_(0.0), SC_(8.0), SC_(0.000146470705222815387096584408698677921967305368833759024089154) }},
        {{ SC_(0.0), T(std::ldexp(1.0, -15)), SC_(10.5131392267382037062459525561594822400447325776672021972753) }},
        {{ SC_(0.0), T(std::ldexp(1.0, -30)), SC_(20.9103469324567717360787328239372191382743831365906131108531) }},
        {{ SC_(0.0), T(std::ldexp(1.0, -60)), SC_(41.7047623492551310138446473188663682295952219631968830346918) }},
        {{ SC_(0.0), SC_(50.0), SC_(3.41016774978949551392067551235295223184502537762334808993276e-23) }},
        {{ SC_(0.0), SC_(100.0), SC_(4.65662822917590201893900528948388635580753948544211387402671e-45) }},
    }};
    static const boost::array<boost::array<T, 3>, 9> k1_data = {{
        {{ SC_(1.0), SC_(1.0), SC_(0.601907230197234574737540001535617339261586889968106456017768) }},
        {{ SC_(1.0), SC_(2.0), SC_(0.139865881816522427284598807035411023887234584841515530384442) }},
        {{ SC_(1.0), SC_(4.0), SC_(0.0124834988872684314703841799808060684838415849886258457917076) }},
        {{ SC_(1.0), SC_(8.0), SC_(0.000155369211805001133916862450622474621117065122872616157079566) }},
        {{ SC_(1.0), T(std::ldexp(1.0, -15)), SC_(32767.9998319528316432647441316539139725104728341577594326513) }},
        {{ SC_(1.0), T(std::ldexp(1.0, -30)), SC_(1.07374182399999999003003028572687332810353799544215073362305e9) }},
        {{ SC_(1.0), T(std::ldexp(1.0, -60)), SC_(1.15292150460684697599999999999999998169660198868126604634036e18) }},
        {{ SC_(1.0), SC_(50.0), SC_(3.44410222671755561259185303591267155099677251348256880221927e-23) }},
        {{ SC_(1.0), SC_(100.0), SC_(4.67985373563690928656254424202433530797494354694335352937465e-45) }},
    }};
    static const boost::array<boost::array<T, 3>, 9> kn_data = {{
        {{ SC_(2.0), T(std::ldexp(1.0, -30)), SC_(2.30584300921369395150000000000000000234841952009593636868109e18) }},
        {{ SC_(5.0), SC_(10.0), SC_(0.0000575418499853122792763740236992723196597629124356739596921536) }},
        {{ SC_(-5.0), SC_(100.0), SC_(5.27325611329294989461777188449044716451716555009882448801072e-45) }},
        {{ SC_(10.0), SC_(10.0), SC_(0.00161425530039067002345725193091329085443750382929208307802221) }},
        {{ SC_(10.0), T(std::ldexp(1.0, -30)), SC_(3.78470202927236255215249281534478864916684072926050665209083e98) }},
        {{ SC_(-10.0), SC_(1.0), SC_(1.80713289901029454691597861302340015908245782948536080022119e8) }},
        {{ SC_(100.0), SC_(5.0), SC_(7.03986019306167654653386616796116726248616158936088056952477e115) }},
        {{ SC_(100.0), SC_(80.0), SC_(8.39287107246490782848985384895907681748152272748337807033319e-12) }},
        {{ SC_(-1000.0), SC_(700.0), SC_(6.51561979144735818903553852606383312984409361984128221539405e-31) }},
    }};
    static const boost::array<boost::array<T, 3>, 11> kv_data = {{
        {{ SC_(0.5), SC_(0.875), SC_(0.558532231646608646115729767013630967055657943463362504577189) }},
        {{ SC_(0.5), SC_(1.125), SC_(0.383621010650189547146769320487006220295290256657827220786527) }},
        {{ SC_(2.25), T(std::ldexp(1.0, -30)), SC_(5.62397392719283271332307799146649700147907612095185712015604e20) }},
        {{ SC_(5.5), T(3217)/1024, SC_(1.30623288775012596319554857587765179889689223531159532808379) }},
        {{ SC_(-5.5), SC_(10.0), SC_(0.0000733045300798502164644836879577484533096239574909573072142667) }},
        {{ SC_(-5.5), SC_(100.0), SC_(5.41274555306792267322084448693957747924412508020839543293369e-45) }},
        {{ T(10240)/1024, T(1)/1024, SC_(2.35522579263922076203415803966825431039900000000993410734978e38) }},
        {{ T(10240)/1024, SC_(10.0), SC_(0.00161425530039067002345725193091329085443750382929208307802221) }},
        {{ T(144793)/1024, SC_(100.0), SC_(1.39565245860302528069481472855619216759142225046370312329416e-6) }},
        {{ T(144793)/1024, SC_(200.0), SC_(9.11950412043225432171915100042647230802198254567007382956336e-68) }},
        {{ T(-144793)/1024, SC_(50.0), SC_(1.30185229717525025165362673848737761549946548375142378172956e42) }},
    }};
    static const boost::array<boost::array<T, 3>, 5> kv_large_data = {{
        // Bug report https://svn.boost.org/trac/boost/ticket/5560:
        {{ SC_(-1.0), static_cast<T>(ldexp(0.5, -512)), SC_(2.68156158598851941991480499964116922549587316411847867554471e154) }},
        {{ SC_(1.0),  static_cast<T>(ldexp(0.5, -512)), SC_(2.68156158598851941991480499964116922549587316411847867554471e154) }},
        {{ SC_(-1.125), static_cast<T>(ldexp(0.5, -512)), SC_(5.53984048006472105611199242328122729730752165907526178753978e173) }},
        {{ SC_(1.125),  static_cast<T>(ldexp(0.5, -512)), SC_(5.53984048006472105611199242328122729730752165907526178753978e173) }},
        {{ SC_(0.5),  static_cast<T>(ldexp(0.5, -683)), SC_(1.12284149973980088540335945247019177715948513804063794284101e103) }},
    }};

    do_test_cyl_bessel_k<T>(k0_data, name, "Bessel K0: Mathworld Data");
    do_test_cyl_bessel_k<T>(k1_data, name, "Bessel K1: Mathworld Data");
    do_test_cyl_bessel_k<T>(kn_data, name, "Bessel Kn: Mathworld Data");

    do_test_cyl_bessel_k_int<T>(k0_data, name, "Bessel K0: Mathworld Data (Integer Version)");
    do_test_cyl_bessel_k_int<T>(k1_data, name, "Bessel K1: Mathworld Data (Integer Version)");
    do_test_cyl_bessel_k_int<T>(kn_data, name, "Bessel Kn: Mathworld Data (Integer Version)");

    do_test_cyl_bessel_k<T>(kv_data, name, "Bessel Kv: Mathworld Data");
    if(0 != static_cast<T>(ldexp(0.5, -512)))
      do_test_cyl_bessel_k<T>(kv_large_data, name, "Bessel Kv: Mathworld Data (large values)");
#include "bessel_k_int_data.ipp"
    do_test_cyl_bessel_k<T>(bessel_k_int_data, name, "Bessel Kn: Random Data");
#include "bessel_k_data.ipp"
    do_test_cyl_bessel_k<T>(bessel_k_data, name, "Bessel Kv: Random Data");
}
コード例 #28
0
ファイル: eml_setop.c プロジェクト: CalilQ/sdruWiLab
/* Function Definitions */
void do_vectors(const emlrtStack *sp, const real_T a_data[1224], const int32_T
                a_size[1], const real_T b[8], real_T c_data[8], int32_T c_size[1],
                int32_T ia_data[8], int32_T ia_size[1], int32_T ib_data[8],
                int32_T ib_size[1])
{
  int32_T ncmax;
  boolean_T y;
  int32_T ialast;
  boolean_T exitg4;
  boolean_T guard9 = FALSE;
  boolean_T p;
  boolean_T exitg3;
  boolean_T guard8 = FALSE;
  int32_T nc;
  int32_T iafirst;
  int32_T ibfirst;
  int32_T iblast;
  int32_T b_ialast;
  real_T ak;
  boolean_T exitg2;
  real_T absxk;
  int32_T exponent;
  boolean_T guard6 = FALSE;
  boolean_T guard7 = FALSE;
  int32_T b_iblast;
  real_T bk;
  boolean_T exitg1;
  int32_T b_exponent;
  boolean_T guard4 = FALSE;
  boolean_T guard5 = FALSE;
  int32_T c_exponent;
  boolean_T guard2 = FALSE;
  boolean_T guard3 = FALSE;
  boolean_T guard1 = FALSE;
  const mxArray *b_y;
  const mxArray *m37;
  int32_T b_ia_data[8];
  const mxArray *c_y;
  const mxArray *d_y;
  real_T b_c_data[8];
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &dw_emlrtRSI;
  ncmax = muIntScalarMin_sint32(a_size[0], 8);
  c_size[0] = (int8_T)ncmax;
  ia_size[0] = ncmax;
  ib_size[0] = ncmax;
  st.site = &ew_emlrtRSI;
  y = TRUE;
  if (a_size[0] == 0) {
  } else {
    ialast = 1;
    exitg4 = FALSE;
    while ((exitg4 == FALSE) && (ialast <= a_size[0] - 1)) {
      guard9 = FALSE;
      if (a_data[ialast - 1] <= a_data[ialast]) {
        guard9 = TRUE;
      } else if (muDoubleScalarIsNaN(a_data[ialast])) {
        guard9 = TRUE;
      } else {
        p = FALSE;
      }

      if (guard9 == TRUE) {
        p = TRUE;
      }

      if (!p) {
        y = FALSE;
        exitg4 = TRUE;
      } else {
        ialast++;
      }
    }
  }

  if (!y) {
    st.site = &fw_emlrtRSI;
    eml_error(&st);
  }

  st.site = &gw_emlrtRSI;
  y = TRUE;
  ialast = 1;
  exitg3 = FALSE;
  while ((exitg3 == FALSE) && (ialast < 8)) {
    guard8 = FALSE;
    if (b[ialast - 1] <= b[ialast]) {
      guard8 = TRUE;
    } else if (muDoubleScalarIsNaN(b[ialast])) {
      guard8 = TRUE;
    } else {
      p = FALSE;
    }

    if (guard8 == TRUE) {
      p = TRUE;
    }

    if (!p) {
      y = FALSE;
      exitg3 = TRUE;
    } else {
      ialast++;
    }
  }

  if (!y) {
    st.site = &hw_emlrtRSI;
    b_eml_error(&st);
  }

  nc = 0;
  iafirst = 0;
  ialast = 0;
  ibfirst = 0;
  iblast = 0;
  while ((ialast + 1 <= a_size[0]) && (iblast + 1 <= 8)) {
    st.site = &iw_emlrtRSI;
    b_ialast = ialast + 1;
    ak = a_data[ialast];
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (b_ialast < a_size[0])) {
      absxk = muDoubleScalarAbs(a_data[ialast] / 2.0);
      if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
        if (absxk <= 2.2250738585072014E-308) {
          absxk = 4.94065645841247E-324;
        } else {
          frexp(absxk, &exponent);
          absxk = ldexp(1.0, exponent - 53);
        }
      } else {
        absxk = rtNaN;
      }

      guard6 = FALSE;
      guard7 = FALSE;
      if (muDoubleScalarAbs(a_data[ialast] - a_data[b_ialast]) < absxk) {
        guard7 = TRUE;
      } else if (muDoubleScalarIsInf(a_data[b_ialast])) {
        if (muDoubleScalarIsInf(a_data[ialast]) && ((a_data[b_ialast] > 0.0) ==
             (a_data[ialast] > 0.0))) {
          guard7 = TRUE;
        } else {
          guard6 = TRUE;
        }
      } else {
        guard6 = TRUE;
      }

      if (guard7 == TRUE) {
        p = TRUE;
      }

      if (guard6 == TRUE) {
        p = FALSE;
      }

      if (p) {
        b_ialast++;
      } else {
        exitg2 = TRUE;
      }
    }

    ialast = b_ialast - 1;
    st.site = &jw_emlrtRSI;
    b_iblast = iblast + 1;
    bk = b[iblast];
    exitg1 = FALSE;
    while ((exitg1 == FALSE) && (b_iblast < 8)) {
      absxk = muDoubleScalarAbs(b[iblast] / 2.0);
      if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
        if (absxk <= 2.2250738585072014E-308) {
          absxk = 4.94065645841247E-324;
        } else {
          frexp(absxk, &b_exponent);
          absxk = ldexp(1.0, b_exponent - 53);
        }
      } else {
        absxk = rtNaN;
      }

      guard4 = FALSE;
      guard5 = FALSE;
      if (muDoubleScalarAbs(b[iblast] - b[b_iblast]) < absxk) {
        guard5 = TRUE;
      } else if (muDoubleScalarIsInf(b[b_iblast])) {
        if (muDoubleScalarIsInf(b[iblast]) && ((b[b_iblast] > 0.0) == (b[iblast]
              > 0.0))) {
          guard5 = TRUE;
        } else {
          guard4 = TRUE;
        }
      } else {
        guard4 = TRUE;
      }

      if (guard5 == TRUE) {
        p = TRUE;
      }

      if (guard4 == TRUE) {
        p = FALSE;
      }

      if (p) {
        b_iblast++;
      } else {
        exitg1 = TRUE;
      }
    }

    iblast = b_iblast - 1;
    st.site = &kw_emlrtRSI;
    absxk = muDoubleScalarAbs(bk / 2.0);
    if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
      if (absxk <= 2.2250738585072014E-308) {
        absxk = 4.94065645841247E-324;
      } else {
        frexp(absxk, &c_exponent);
        absxk = ldexp(1.0, c_exponent - 53);
      }
    } else {
      absxk = rtNaN;
    }

    guard2 = FALSE;
    guard3 = FALSE;
    if (muDoubleScalarAbs(bk - ak) < absxk) {
      guard3 = TRUE;
    } else if (muDoubleScalarIsInf(ak)) {
      if (muDoubleScalarIsInf(bk) && ((ak > 0.0) == (bk > 0.0))) {
        guard3 = TRUE;
      } else {
        guard2 = TRUE;
      }
    } else {
      guard2 = TRUE;
    }

    if (guard3 == TRUE) {
      p = TRUE;
    }

    if (guard2 == TRUE) {
      p = FALSE;
    }

    if (p) {
      st.site = &lw_emlrtRSI;
      nc++;
      c_data[nc - 1] = ak;
      ia_data[nc - 1] = iafirst + 1;
      ib_data[nc - 1] = ibfirst + 1;
      st.site = &mw_emlrtRSI;
      ialast = b_ialast;
      iafirst = b_ialast;
      st.site = &nw_emlrtRSI;
      iblast = b_iblast;
      ibfirst = b_iblast;
    } else {
      st.site = &ow_emlrtRSI;
      guard1 = FALSE;
      if (ak < bk) {
        guard1 = TRUE;
      } else if (muDoubleScalarIsNaN(bk)) {
        guard1 = TRUE;
      } else {
        p = FALSE;
      }

      if (guard1 == TRUE) {
        p = TRUE;
      }

      if (p) {
        st.site = &pw_emlrtRSI;
        ialast = b_ialast;
        iafirst = b_ialast;
      } else {
        st.site = &qw_emlrtRSI;
        iblast = b_iblast;
        ibfirst = b_iblast;
      }
    }
  }

  if (ncmax > 0) {
    if (nc <= ncmax) {
    } else {
      b_y = NULL;
      m37 = mxCreateString("Assertion failed.");
      emlrtAssign(&b_y, m37);
      st.site = &kbb_emlrtRSI;
      c_error(&st, b_y, &hb_emlrtMCI);
    }

    if (1 > nc) {
      ialast = 0;
    } else {
      ialast = nc;
    }

    for (iafirst = 0; iafirst < ialast; iafirst++) {
      b_ia_data[iafirst] = ia_data[iafirst];
    }

    ia_size[0] = ialast;
    for (iafirst = 0; iafirst < ialast; iafirst++) {
      ia_data[iafirst] = b_ia_data[iafirst];
    }
  }

  if (ncmax > 0) {
    if (nc <= ncmax) {
    } else {
      c_y = NULL;
      m37 = mxCreateString("Assertion failed.");
      emlrtAssign(&c_y, m37);
      st.site = &jbb_emlrtRSI;
      c_error(&st, c_y, &ib_emlrtMCI);
    }

    if (1 > nc) {
      ialast = 0;
    } else {
      ialast = nc;
    }

    for (iafirst = 0; iafirst < ialast; iafirst++) {
      b_ia_data[iafirst] = ib_data[iafirst];
    }

    ib_size[0] = ialast;
    for (iafirst = 0; iafirst < ialast; iafirst++) {
      ib_data[iafirst] = b_ia_data[iafirst];
    }
  }

  if (ncmax > 0) {
    if (nc <= ncmax) {
    } else {
      d_y = NULL;
      m37 = mxCreateString("Assertion failed.");
      emlrtAssign(&d_y, m37);
      st.site = &ibb_emlrtRSI;
      c_error(&st, d_y, &jb_emlrtMCI);
    }

    if (1 > nc) {
      ialast = 0;
    } else {
      ialast = nc;
    }

    for (iafirst = 0; iafirst < ialast; iafirst++) {
      b_c_data[iafirst] = c_data[iafirst];
    }

    c_size[0] = ialast;
    for (iafirst = 0; iafirst < ialast; iafirst++) {
      c_data[iafirst] = b_c_data[iafirst];
    }
  }
}
コード例 #29
0
/* Returns the number of sound data frames or negative on error */
static unsigned int get_aiff_header(AVFormatContext *s, int size,
                                    unsigned version)
{
    AVIOContext *pb        = s->pb;
    AVCodecContext *codec  = s->streams[0]->codec;
    AIFFInputContext *aiff = s->priv_data;
    int exp;
    uint64_t val;
    double sample_rate;
    unsigned int num_frames;

    if (size & 1)
        size++;
    codec->codec_type = AVMEDIA_TYPE_AUDIO;
    codec->channels = avio_rb16(pb);
    num_frames = avio_rb32(pb);
    codec->bits_per_coded_sample = avio_rb16(pb);

    exp = avio_rb16(pb);
    val = avio_rb64(pb);
    sample_rate = ldexp(val, exp - 16383 - 63);
    codec->sample_rate = sample_rate;
    size -= 18;

    /* get codec id for AIFF-C */
    if (version == AIFF_C_VERSION1) {
        codec->codec_tag = avio_rl32(pb);
        codec->codec_id  = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag);
        size -= 4;
    }

    if (version != AIFF_C_VERSION1 || codec->codec_id == AV_CODEC_ID_PCM_S16BE) {
        codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
        codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
        aiff->block_duration = 1;
    } else {
        switch (codec->codec_id) {
        case AV_CODEC_ID_PCM_F32BE:
        case AV_CODEC_ID_PCM_F64BE:
        case AV_CODEC_ID_PCM_S16LE:
        case AV_CODEC_ID_PCM_ALAW:
        case AV_CODEC_ID_PCM_MULAW:
            aiff->block_duration = 1;
            break;
        case AV_CODEC_ID_ADPCM_IMA_QT:
            codec->block_align = 34*codec->channels;
            break;
        case AV_CODEC_ID_MACE3:
            codec->block_align = 2*codec->channels;
            break;
        case AV_CODEC_ID_MACE6:
            codec->block_align = 1*codec->channels;
            break;
        case AV_CODEC_ID_GSM:
            codec->block_align = 33;
            break;
        default:
            aiff->block_duration = 1;
            break;
        }
        if (codec->block_align > 0)
            aiff->block_duration = av_get_audio_frame_duration(codec,
                                                               codec->block_align);
    }

    /* Block align needs to be computed in all cases, as the definition
     * is specific to applications -> here we use the WAVE format definition */
    if (!codec->block_align)
        codec->block_align = (av_get_bits_per_sample(codec->codec_id) * codec->channels) >> 3;

    if (aiff->block_duration) {
        codec->bit_rate = codec->sample_rate * (codec->block_align << 3) /
                          aiff->block_duration;
    }

    /* Chunk is over */
    if (size)
        avio_skip(pb, size);

    return num_frames;
}
コード例 #30
0
void test_extra(T)
{
   T t = 1;
   t = abs(t);
   t = abs(t*t);

   t = fabs(t);
   t = fabs(t*t);

   t = sqrt(t);
   t = sqrt(t*t);

   t = floor(t);
   t = floor(t*t);

   t = ceil(t);
   t = ceil(t*t);

   t = trunc(t);
   t = trunc(t*t);

   t = round(t);
   t = round(t*t);

   t = exp(t);
   t = exp(t*t);

   t = log(t);
   t = log(t*t);

   t = log10(t);
   t = log10(t*t);

   t = cos(t);
   t = cos(t*t);

   t = sin(t);
   t = sin(t*t);

   t = tan(t);
   t = tan(t*t);

   t = asin(t);
   t = asin(t*t);

   t = atan(t);
   t = atan(t*t);

   t = acos(t);
   t = acos(t*t);

   t = cosh(t);
   t = cosh(t*t);

   t = sinh(t);
   t = sinh(t*t);

   t = tanh(t);
   t = tanh(t*t);

   double dval = 2;
   t = pow(t, t);
   t = pow(t, t*t);
   t = pow(t, dval);
   t = pow(t*t, t);
   t = pow(t*t, t*t);
   t = pow(t*t, dval);
   t = pow(dval, t);
   t = pow(dval, t*t);

   t = atan2(t, t);
   t = atan2(t, t*t);
   t = atan2(t, dval);
   t = atan2(t*t, t);
   t = atan2(t*t, t*t);
   t = atan2(t*t, dval);
   t = atan2(dval, t);
   t = atan2(dval, t*t);

   t = fmod(t, t);
   t = fmod(t, t*t);
   t = fmod(t, dval);
   t = fmod(t*t, t);
   t = fmod(t*t, t*t);
   t = fmod(t*t, dval);
   t = fmod(dval, t);
   t = fmod(dval, t*t);

   typedef typename T::backend_type backend_type;
   typedef typename backend_type::exponent_type exp_type;
   exp_type e = 0;
   int i = 0;

   t = ldexp(t, i);
   t = ldexp(t*t, i);
   t = ldexp(t, e);
   t = ldexp(t*t, e);

   t = frexp(t, &i);
   t = frexp(t*t, &i);
   t = frexp(t, &e);
   t = frexp(t*t, &e);
}