void moveodd_even1(int s[], int n)
{
	if(s == NULL || n == 0)
	{
		return;
	}

	int counter = 0;
	int l = 0;
	int r = n - 1;
	while(l < r)
	{
		counter++;
		if(isOdd(s[l]))
		{
			l++;
		}
		else if(!isOdd(s[r]))
		{
			r--;
		}
		else
		{
			swap(&s[l], &s[r]);
		}
	}
	printf("%d\n", counter);			
}
Exemple #2
0
ToonzExt::OddInt::operator int()
//throw(std::range_error)
{
	if (!isOdd())
		throw std::range_error("Value is Even!!!");
	return val_;
}
// return 0 with unknown SQL type.
// else, return SQL_TYPE
base::sql_type sqlTypeFor(long serialTypeValue) {
    sTypeSqlTypeMap smap = serialTypeSqlTypeMap();
    base::sql_type sqlType;
    if (0 <= serialTypeValue && serialTypeValue <= 9) {
        sTypeSqlTypeMap::iterator smap_pos;
        smap_pos = smap.find(static_cast<int>(serialTypeValue));
        sqlType = smap_pos->second;
    } else if (serialTypeValue >= 12 && !isOdd(serialTypeValue)) {
        sqlType = base::SQL_TYPE_BLOB;
    } else if (serialTypeValue >= 13 && isOdd(serialTypeValue)) {
        sqlType = base::SQL_TYPE_TEXT;
    } else {
        
        sqlType = 0;
    }
    return sqlType;
}
Exemple #4
0
int KWQQuizModel::column(int i)
{
    int result  = 0;
    if (isOdd(m_quizMode))
        result = 1;
    if ((m_quizMode == 5) && qAbs(i) == i)
        result = 0;
    return result;
}
int isEven(int n) {
    if (n == 0) {
        return 1;
    } else if (n == 1) {
        return 0;
    } else {
        return isOdd(n - 1);
    }
}
Exemple #6
0
std::string dashInsert(int number)
{
	std::string result;
	std::string numberString = std::to_string(number);
	int stringSize = numberString.size();
	char charToInsert = '-';

	result.push_back(numberString[0]);
	for(int i=1; i <= stringSize-1; ++i)
	{
		if(isOdd(numberString[i-1]) && isOdd(numberString[i]))
			result.push_back(charToInsert);

		result.push_back(numberString[i]);
		
	}
	return result;
}
Exemple #7
0
main() 
{
    int v1, v2;      // hold values from user

    read2( v1, v2 ); 

    cout << v1;
    if ( isOdd( v1 ) == 1 )
	cout << " is odd\n";
    else 
	cout << " is even\n";

    cout << v2; 
    if ( isOdd( v2 ) == 1 )
	cout << " is odd\n";
    else
	cout << " is even\n";

    return 0;
}
void ExtBinEuclid(int *u, int *v, int *u1, int *u2, int *u3)
{
	// warning: u, v will be swapped if u < v
	int k, t1, t2, t3;

	if(*u < *v){
		swap(*u, *v);
	}
	for(k = 0; isEven(*u) && isEven(*v); k++){
		*u >>= 1;
		*v >>= 1;
	}

	*u1 = 1; *u2 = 0; *u3 = *u; t1 = *v; t2 = *u-1; t3 = *v;
	do{
		do{
			if(isEven(*u3)){
				if(isOdd(*u1) || isOdd(*u2)){
					*u1 += *v; *u2 += *u;
				}
				*u1 >>= 1; *u2 >>= 1; *u3 >>= 1;
			}
			if(isEven(t3) || *u3 < t3){
				swap(*u1, t1); swap(*u2, t2); swap(*u3, t3);
			}
		} while(isEven(*u3));

		while(*u1 < t1 || *u2 < t2){
			*u1 += *v; *u2 += *u;
		}

		*u1 -= t1; *u2 -= t2; *u3 -= t3;

	} while(t3 > 0);

	while(*u1 >= *v && *u2 < *u){
		*u1 -= *v; *u2 -= *u;
	}

	*u1 <<= k; *u2 <<= k; *u3 <<= k;
}
Exemple #9
0
void main()
{
    //Test Variables
    int year, leap, num, num2, month, day, bitCount;
    month = 2;
    num = 22;
    num2 = 37;
    year = 2004;
    day = daysInMonth(month, year);
    bitCount = countOnes(num);
    leap = isLeap(year);

    //Testing countOnes
    printf("The number of bits in %u is %d\n", num, bitCount);

    //Testing isEven
    if (isEven(num))
    {
        printf("%d is an even number\n", num);
    }
    else
    {
        printf("%d is not an even number\n", num);
    }

    //Testing isOdd
    if (isOdd(num2))
    {
        printf("%d is an odd number\n", num2);
    }
    else
    {
        printf("%d is not an odd number\n", num2);
    }

    //Testing isLeap
    if (leap == 1)
    {
        printf("The year %d is a leap year\n",year);
    }
    else
    {
        printf("The year %d is not a leap year\n",year);
    }

    //Testing daysInMonth
    printf("Febuary has %d days in the year %d\n",day, year);

    //Testing packChars
    printf("Packing %d and %d together forms 0x%x\n", 3, 5, packChars(3,5));

    getchar();
}
Exemple #10
0
void Geometry::setMultiplicity(int const multiplicity)
{
   m_multiplicity = multiplicity;
   int numberOfElectrons(totalNuclearCharge()-m_charge);
   if (isEven(m_multiplicity)) {
      if (isEven(numberOfElectrons)) {
         m_charge += m_charge > 0 ? -1 : 1;
      }
   }else {
      if (isOdd(numberOfElectrons)) {
         m_charge += (numberOfElectrons == 1) ? -1 : 1;
      }
   }
}
Exemple #11
0
void Geometry::setCharge(int const charge)
{
   m_charge = charge;
   int numberOfElectrons(totalNuclearCharge()-m_charge);
   if (isEven(numberOfElectrons)) {
      if (isEven(m_multiplicity)) {
         m_multiplicity -= 1;
      }
   }else {
      if (isOdd(m_multiplicity)) {
          m_multiplicity += (m_multiplicity == 1) ? 1 : -1;
      }
   }
}
Exemple #12
0
inline void alignRectBy2(qint32 &x, qint32 &y, qint32 &w, qint32 &h)
{
    x -= isOdd(x);
    y -= isOdd(y);
    w += isOdd(x);
    w += isOdd(w);
    h += isOdd(y);
    h += isOdd(h);
}
int main(void){
	int i, j = 0;

	scanf("%s", num);
	N = strlen(num);

	for (i = 0; i < N; i++)
		num[i] -= '0';

	for (i = 1; i < N; i++){
		if (num[i] + num[i-1] != 9){
			if (isOdd(i-j))
				ans *= (i-j+1)/2;
			j = i;
		}
	}

	if (isOdd(i-j))
		ans *= (i-j+1)/2;

	printf("%llu\n", ans);

	return 0;
}
int isEven(int n) {
    int ret;
    if (n == 0) {
        /* return 1; */
        ret = 1; goto RET_isEven;
    } else if (n == 1) {
        /* return 0; */
        ret = 0; goto RET_isEven;
    } else {
        /* return isOdd(n - 1); */
        isOdd(n - 1);
        ret = get_isOdd(); goto RET_isEven;
    }
RET_isEven:
    set_isEven(ret);
}
Exemple #15
0
int64_t Problem2::solve()
{
    int64_t sum = 0;
    Fibonacci<int64_t> fibonacci;

    int i = 1;
    int64_t current = fibonacci.getNth(i++);
    while(current <= MAX)
    {
        if(!isOdd(current))
            sum += current;

        current = fibonacci.getNth(i++);
    }

    return sum;
}
Exemple #16
0
QRect KisImagePyramid::downsampleByFactor2(const QRect& srcRect,
        KisPaintDevice* src,
        KisPaintDevice* dst)
{
    qint32 srcX, srcY, srcWidth, srcHeight;
    srcRect.getRect(&srcX, &srcY, &srcWidth, &srcHeight);
    alignRectBy2(srcX, srcY, srcWidth, srcHeight);

    // Nothing to do
    if (srcWidth < 1) return QRect();
    if (srcHeight < 1) return QRect();

    qint32 dstX = srcX / 2;
    qint32 dstY = srcY / 2;
    qint32 dstWidth = srcWidth / 2;
    qint32 dstHeight = srcHeight / 2;

    KisHLineConstIteratorSP srcIt0 = src->createHLineConstIteratorNG(srcX, srcY, srcWidth);
    KisHLineConstIteratorSP srcIt1 = src->createHLineConstIteratorNG(srcX, srcY + 1, srcWidth);
    KisHLineIteratorSP dstIt = dst->createHLineIteratorNG(dstX, dstY, dstWidth);

    int conseqPixels = 0;
    for (int row = 0; row < dstHeight; ++row) {
        do {
            int srcItConseq = srcIt0->nConseqPixels();
            int dstItConseq = dstIt->nConseqPixels();
            conseqPixels = qMin(srcItConseq, dstItConseq * 2);

            Q_ASSERT(!isOdd(conseqPixels));

            downsamplePixels(srcIt0->oldRawData(), srcIt1->oldRawData(),
                             dstIt->rawData(), conseqPixels);


            srcIt1->nextPixels(conseqPixels);
            dstIt->nextPixels(conseqPixels / 2);
        } while (srcIt0->nextPixels(conseqPixels));
        srcIt0->nextRow();
        srcIt0->nextRow();
        srcIt1->nextRow();
        srcIt1->nextRow();
        dstIt->nextRow();
    }
    return QRect(dstX, dstY, dstWidth, dstHeight);
}
Exemple #17
0
int main(int argc, const char* argv[])
{
    int i;
    printf("add(3, 8)   = %i\n", add(3, 8));
    printf("add(36, 81) = %i\n", add(36, 81));
    printf("gcd(36, 81) = %i\n", gcd(36, 81));
    for (i = 0; i < 20; i++) {
        printf("\n");
        printf("fib(%i)        = %i\n", i, fib(i));
        printf("isEven(%i)     = %i\n", i, isEven(i));
        printf("isOdd(%i)      = %i\n", i, isOdd(i));
        printf("power(1.5, %i) = %f\n", i, power(1.5, i));
    }
    printf("distSqOf789() = %f\n", distSqOf789());
    printf("avgOfFour(10.0, 25.0, 75.0, 90.0) = %f\n", avgOfFour(10.0, 25.0, 75.0, 90.0));
    
    return 0;
}
cManager::cManager(vector<cSquare*> &vSquareVector)
{
	vector<cSquare*> vOwnedProperties;

	//Uses A Const To Determine The Amount Of Rounds
	int managerRounds[amountOfRounds];

	//Outputs A Welcoming Message To User
	cout << "Welcome To Monopoly." << endl;

	//Reads The Monopoly.txt File And Creates Pointers Of Classes
	retrieveFile(vSquareVector);

	//Uses The Amount Of Rounds Const To Determine The Random's Length
	roll(managerRounds);

	//Creates The Objects Of cPlayer Class.
	cPlayer Player1("Dog", 300, 0);
	cPlayer Player2("Car", 300, 0);

	//Uses The Amount Of Rounds To Determine Howmany Times To Loop
	for (int i = 0; i < amountOfRounds; i++)
	{
		// Splits Evenly For Each Use(Odd 1 Player , Even The Other)
		if (isOdd(i) == true)
		{
			diceLocationMove(Player1.getCurrentPosition(), managerRounds[i], Player1);
			squareLocation(Player1.getCurrentPosition(), Player1, Player2, vSquareVector);
			checkPlayerBalance(Player1);

		}
		else
		{
			diceLocationMove(Player2.getCurrentPosition(), managerRounds[i], Player2);
			squareLocation(Player2.getCurrentPosition(), Player2, Player1, vSquareVector);
			checkPlayerBalance(Player2);

		}
	}
	clearMemory(vSquareVector);
}
QRect KisImagePyramid::downsampleByFactor2(const QRect& srcRect,
        KisPaintDevice* src,
        KisPaintDevice* dst)
{
    qint32 srcX, srcY, srcWidth, srcHeight;
    srcRect.getRect(&srcX, &srcY, &srcWidth, &srcHeight);
    alignRectBy2(srcX, srcY, srcWidth, srcHeight);

    qint32 dstX = srcX / 2;
    qint32 dstY = srcY / 2;
    qint32 dstWidth = srcWidth / 2;
    qint32 dstHeight = srcHeight / 2;

    KisHLineConstIteratorPixel srcIt0 = src->createHLineConstIterator(srcX, srcY, srcWidth);
    KisHLineConstIteratorPixel srcIt1 = src->createHLineConstIterator(srcX, srcY + 1, srcWidth);
    KisHLineIteratorPixel dstIt = dst->createHLineIterator(dstX, dstY, dstWidth);

    for (int row = 0; row < dstHeight; ++row) {
        while (!dstIt.isDone()) {
            int srcItConseq = srcIt0.nConseqHPixels();
            int dstItConseq = dstIt.nConseqHPixels();
            int conseqPixels = qMin(srcItConseq, dstItConseq * 2);

            Q_ASSERT(!isOdd(conseqPixels));

            downsamplePixels(srcIt0.rawData(), srcIt1.rawData(),
                             dstIt.rawData(), conseqPixels);

            srcIt0 += conseqPixels;
            srcIt1 += conseqPixels;
            dstIt += conseqPixels / 2;
        }
        srcIt0.nextRow();
        srcIt0.nextRow();
        srcIt1.nextRow();
        srcIt1.nextRow();
        dstIt.nextRow();
    }
    return QRect(dstX, dstY, dstWidth, dstHeight);
}
void moveodd_even2(int s[], int n)
{
	if(s == NULL || n == 0)
	{
		return;
	}
	int l = 0;
	int r = n - 1;
	int x = s[r];

	int i = l - 1;
	for(int j = l; j <= r - 1; j++)
	{
		if(isOdd(s[j]))
		{
			i = i + 1;
			swap(&s[i], &s[j]);
		}
	}

	swap(&s[i + 1], &s[r]);
}
Exemple #21
0
void Fourier::shuffleFourierToNaturalOrder (fftw_complex* pVector, const int n)
{
  fftw_complex* pTemp = static_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * n));
  int i;
  if (isOdd(n)) { // Odd
    int iHalfN = (n - 1) / 2;

    pTemp[iHalfN][0] = pVector[0][0];
    pTemp[iHalfN][1] = pVector[0][1];
    for (i = 0; i < iHalfN; i++) {
      pTemp[i + 1 + iHalfN][0] = pVector[i + 1][0];
      pTemp[i + 1 + iHalfN][1] = pVector[i + 1][1];
    }
    for (i = 0; i < iHalfN; i++) {
      pTemp[i][0] = pVector[i + iHalfN + 1][0];
      pTemp[i][1] = pVector[i + iHalfN + 1][1];
    }
  } else {     // Even
    int iHalfN = n / 2;
    pTemp[iHalfN][0] = pVector[0][0];
    pTemp[iHalfN][1] = pVector[0][1];
    for (i = 0; i < iHalfN; i++) {
      pTemp[i][0] = pVector[i + iHalfN][0];
      pTemp[i][1] = pVector[i + iHalfN][1];
    }
    for (i = 0; i < iHalfN - 1; i++) {
      pTemp[i + iHalfN + 1][0] = pVector[i+1][0];
      pTemp[i + iHalfN + 1][1] = pVector[i+1][1];
    }
  }

  for (i = 0; i < n; i++) {
    pVector[i][0] = pTemp[i][0];
    pVector[i][1] = pTemp[i][1];
  }

  fftw_free(pTemp);
}
Exemple #22
0
int main(void){
    int squareSize;
    int** square;
    
    //Grabbing initial input
    printf("This program creates a magic square if a specified size.\nThe size must be an odd number between 1 and 99.\n");
    printf("Enter size of magic square: ");
    scanf("%i", &squareSize);
    
    // Some basic error checking
    while(!isOdd(squareSize)){
        printf("The size must be an odd number between 1 and 99.\n");
        printf("Enter size of magic square: ");
        scanf("%i", &squareSize);
    }
    
    //Building and printing square
    square = buildSquare(squareSize);
    printSquare(square, squareSize);
    free(square);
    
    return 0;
}
Exemple #23
0
void iir_coeff::make_band(float_type c) {
  center_freq = c;
  c0 = cos(center_freq*2*M_PI); 
  std::vector<std::complex<float_type> > old_poles;
  std::vector<std::complex<float_type> > old_zeros;

  for (size_t i = 0; i < poles.size(); i++) {
    old_poles.push_back(poles[i]);
    old_zeros.push_back(zeros[i]);
  }

  int was_odd = isOdd();

  resize(2 * getOrder());

  float q = -1;
  // q should be 1 for bandpass,- 1 for bandstop
  if (lpf == filter_type::bandpass) q = 1;

  int k = 0;
  // For Original odd order filters, skip the 1st pole/zero
  for (int j = was_odd; j < was_odd + n2 / 2; j++) {
    std::complex<float_type> pi = -old_poles[j];
    std::complex<float_type> zi = -old_zeros[j];
    std::complex<float_type> p0 = c0 * (1.0 + q * pi);
    std::complex<float_type> z0 = c0 * (1.0 + q * zi);
    poles[k] = 0.5 * (p0 + sqrt(p0 * p0 - 4 * q * pi));
    poles[k + n2 / 2] = (c0 - poles[k]) / (1.0 - c0 * poles[k]);
    zeros[k] = 0.5 * (z0 + sqrt(z0 * z0 - 4 * q * zi));
    zeros[k + n2 / 2] = (c0 - zeros[k]) / (1.0 - c0 * zeros[k]);
    k++;
  }

  // Convert from poles/zeros to transfer function (except 1st pole/zero for odd original size)
  convert_to_ab();

  // if originally even, we are done, otherwise
  if (was_odd) {
    // Resize a_tf,b_tf (for now) by removing last 2 elements
    a_tf.pop_back();
    a_tf.pop_back();
    b_tf.pop_back();
    b_tf.pop_back();
    // Actual polynomials will be real only
    std::vector<float_type> p = {1, 0, 0};
    // For bandpass zeros are always like this, even for different center frequencies!!!
    std::vector<float_type> z = {1, 0, -1};
    // Page 29, 111, 112
    if (lpf != filter_type::bandpass) {
      z[1] = -2 * c0;
      z[2] = 1;
    }
    std::complex<float_type> p0h = -old_poles[0];
    std::complex<float_type> p0h_s = c0 * (1 + q * p0h);
    std::complex<float_type> p0p = 0.5 * (p0h_s + sqrt(p0h_s * p0h_s - 4 * q * p0h));
    // std::complex<float_type> p0m = 0.5*(p0h_s - sqrt(p0h_s*p0h_s - 4*q*p0h));

    p[1] = -2 * real(p0p);
    p[2] = std::real(norm(p0p));
    // Adds back last two elements with new convolved result
    b_tf = convolve(z, b_tf);
    a_tf = convolve(p, a_tf);
  }
}
Exemple #24
0
static void parseTagLine (tagFile *file, tagEntry *const entry)
{
	int i;
	char *p = file->line.buffer;
	size_t p_len = strlen (p);
	char *tab = strchr (p, TAB);

	memset(entry, 0, sizeof(*entry));

	entry->name = p;
	if (tab != NULL)
	{
		*tab = '\0';
	}
	while (*p != '\0')
	{
		const char *next = p;
		int ch = readTagCharacter (&next);
		size_t skip = next - p;

		*p = (char) ch;
		p++;
		p_len -= skip;
		if (skip > 1)
		{
			memmove (p, next, p_len);
			tab -= skip - 1;
		}
	}

	if (tab != NULL)
	{
		p = tab + 1;
		entry->file = p;
		tab = strchr (p, TAB);
		if (tab != NULL)
		{
			int fieldsPresent;
			*tab = '\0';
			p = tab + 1;
			if (*p == '/'  ||  *p == '?')
			{
				/* parse pattern */
				int delimiter = *(unsigned char*) p;
				entry->address.lineNumber = 0;
				entry->address.pattern = p;
				do
				{
					p = strchr (p + 1, delimiter);
				} while (p != NULL
					 &&  isOdd (countContinuousBackslashesBackward (p - 1,
											entry->address.pattern)));

				if (p == NULL)
				{
					/* invalid pattern */
				}
				else
					++p;
			}
			else if (isdigit ((int) *(unsigned char*) p))
			{
				/* parse line number */
				entry->address.pattern = p;
				entry->address.lineNumber = atol (p);
				while (isdigit ((int) *(unsigned char*) p))
					++p;
			}
			else
			{
				/* invalid pattern */
			}

			if (p)
			{
				fieldsPresent = (strncmp (p, ";\"", 2) == 0);
				*p = '\0';
				if (fieldsPresent)
					parseExtensionFields (file, entry, p + 2);
			}
		}
	}
	if (entry->fields.count > 0)
		entry->fields.list = file->fields.list;
	for (i = entry->fields.count  ;  i < file->fields.max  ;  ++i)
	{
		file->fields.list [i].key = NULL;
		file->fields.list [i].value = NULL;
	}
}
Exemple #25
0
// __expected:isEven(number => $_retval)
char isEven(int number) {
  if (number == 0)
    return true;
  else
    return isOdd(abs(number) - 1);
}
Exemple #26
0
void GuiTextBox::render(RenderDevice* rd, const shared_ptr<GuiTheme>& theme, bool ancestorsEnabled) const {
    (void)rd;
    (void)theme;
    GuiTextBox* me = const_cast<GuiTextBox*>(this);

    if (m_visible) {
        if (m_editing) {
            if (! focused()) {
                // Just lost focus
                if ((m_update == DELAYED_UPDATE) && (m_oldValue != m_userValue)) {
                    me->m_oldValue = m_userValue;
                    me->commit();
                    GEvent response;
                    response.gui.type = GEventType::GUI_CHANGE;
                    response.gui.control = me->m_eventSource;
                    m_gui->fireEvent(response);
                }
                me->m_editing = false;
            } else if (String(*m_value) != m_oldValue) {
                // The value has been changed by the program while we
                // were editing; override our copy with the
                // programmatic value.
                me->m_userValue = *m_value;
                me->m_cursorPos = min(m_cursorPos, (int)m_userValue.size());
            }
        } else if (focused()) {
            // Just gained focus
            me->m_userValue = *m_value;
            me->m_oldValue  = m_userValue;
            me->m_editing   = true;
        }

        static RealTime then = System::time();
        RealTime now = System::time();

        bool hasKeyDown = (m_repeatKeysym.sym != GKey::UNKNOWN);

        // Amount of time that the last simulation step took.  
        // This is used to limit the key repeat rate
        // so that it is not faster than the frame rate.
        RealTime frameTime = then - now;

        // If a key is being pressed, process it on a steady repeat schedule.
        if (hasKeyDown && (now > m_keyRepeatTime)) {
            me->processRepeatKeysym();
            me->m_keyRepeatTime = max(now + frameTime * 1.1, now + 1.0 / keyRepeatRate);
        }
        then = now;

        // Only blink the cursor when keys are not being pressed or
        // have not recently been pressed.
        bool solidCursor = hasKeyDown || (now - m_keyRepeatTime < 1.0 / blinkRate);
        if (! solidCursor) {
            static const RealTime zero = System::time();
            solidCursor = isOdd((int)((now - zero) * blinkRate));
        }

        // Note that textbox does not have a mouseover state
        theme->renderTextBox
           (m_rect,
            m_enabled && ancestorsEnabled,
            focused(), 
            m_caption,
            m_captionWidth,
            m_editing ? m_userValue : *m_value, 
            solidCursor ? m_cursor : GuiText(),
            m_cursorPos,
            m_style);
    }
}
Exemple #27
0
Fichier : 100.c Projet : rollen/uva
void testIsOdd(){
  assert(TRUE == isOdd(3));
  assert(TRUE == isOdd(1));
  assert(FALSE == isOdd(4));
}
Exemple #28
0
	double computeMFLOPS(const dvector_t & tim, const double mflo, Tag::TimeSelect ts )
	{
		linbox_check(tim.size());
		switch (ts) {
		case (Tag::TimeSelect::average) :
			{
				double tps = 0 ;
				for (size_t i = 0 ; i < tim.size() ; ++i)
					tps += tim[i] ;
				return computeMFLOPS(tps,mflo,(size_t)tim.size());
			}
		case (Tag::TimeSelect::bestThree) :
			{
				if (tim.size() <4)
					return computeMFLOPS(tim,mflo,Tag::TimeSelect::average);

				dvector_t tps (3);
				double t1,t2 ;
				if (tim[0]<tim[1]) {
					t1 = tim[0];
					t2 = tim[1];
				}
				else {
					t1 = tim[1];
					t2 = tim[0];
				}
				if (tim[3] < t1) {
					tps[0] = tim[3] ;
					tps[1] = t1 ;
					tps[2] = t2 ;
				}
				else if (tim[2] < t1) {
					tps[0] = t1 ;
					tps[1] = tim[3] ;
					tps[2] = t2 ;
				}
				else {
					tps[0] = t1 ;
					tps[1] = t2;
					tps[2] = tim[3] ;
				}

				for (size_t i = 3 ; i < tim.size() ; ++i)
					insertTime(tps,tim[i]);

				return computeMFLOPS(tim,mflo,Tag::TimeSelect::average);

			}
		case (Tag::TimeSelect::bestOne) :
			{
				double t1 = tim[0] ;
				for (size_t i = 1 ; i < tim.size() ; ++i)
					if (tim[i] < t1)
						t1 = tim[i] ;
				return computeMFLOPS(t1,mflo,1);

			}
		case (Tag::TimeSelect::median) :
			{
				if (tim.size() == 1)
					return computeMFLOPS(tim[0],mflo,1) ;

				dvector_t tps (tim);
				std::sort(tps.begin(),tps.end());
				size_t mid = (size_t)tps.size()/2 ;
				double t1 ;
				if (isOdd((uint64_t)tps.size()))
					t1 = tps[mid] ;
				else
					t1 = (tps[mid-1]+tps[mid])/2;
				return computeMFLOPS(t1,mflo,1);
			}
		case (Tag::TimeSelect::medmean) :
			{
				if (tim.size() < 3)
					return computeMFLOPS(tim,mflo,Tag::TimeSelect::median); ;

				size_t q1 = (size_t)((double)tim.size()/(double)4) ;
				size_t q3 = (size_t)tim.size()-q1 ;
				dvector_t tps (tim);
				std::sort(tps.begin(),tps.end());
				dvector_t tps2 (tim.begin()+q1,tim.begin()+q3);
				return computeMFLOPS(tps2,mflo,Tag::TimeSelect::average);
			}

		default :
			{
				throw("not among tags");
			}

		} // switch(ts)
	}
Exemple #29
0
bool MyInt::isEven()
{
    return !isOdd();
}
Exemple #30
0
static void parseTagLine (tagFile *file, tagEntry *const entry)
{
	int i;
	char *p = file->line.buffer;
	char *tab = strchr (p, TAB);

	entry->fields.list = NULL;
	entry->fields.count = 0;
	entry->kind = NULL;
	entry->fileScope = 0;

	entry->name = p;
	if (tab != NULL)
	{
		*tab = '\0';
		p = tab + 1;
		entry->file = p;
		tab = strchr (p, TAB);
		if (tab != NULL)
		{
			int fieldsPresent;
			*tab = '\0';
			p = tab + 1;
			if (*p == '/'  ||  *p == '?')
			{
				/* parse pattern */
				int delimiter = *(unsigned char*) p;
				entry->address.lineNumber = 0;
				entry->address.pattern = p;
				do
				{
					p = strchr (p + 1, delimiter);
				} while (p != NULL
					 &&  isOdd (countContinuousBackslashesBackward (p - 1,
											entry->address.pattern)));

				if (p == NULL)
				{
					/* invalid pattern */
				}
				else
					++p;
			}
			else if (isdigit ((int) *(unsigned char*) p))
			{
				/* parse line number */
				entry->address.pattern = p;
				entry->address.lineNumber = atol (p);
				while (isdigit ((int) *(unsigned char*) p))
					++p;
			}
			else
			{
				/* invalid pattern */
			}
			fieldsPresent = (strncmp (p, ";\"", 2) == 0);
			*p = '\0';
			if (fieldsPresent)
				parseExtensionFields (file, entry, p + 2);
		}
	}
	if (entry->fields.count > 0)
		entry->fields.list = file->fields.list;
	for (i = entry->fields.count  ;  i < file->fields.max  ;  ++i)
	{
		file->fields.list [i].key = NULL;
		file->fields.list [i].value = NULL;
	}
}