Exemplo n.º 1
0
//--------------------------------------------------
// Description  : Get key status
// Input Value  : None
// Output Value : Return Key status
//--------------------------------------------------
BYTE CKeyScan(void)
{
    BYTE ucKeyState = _NONE_KEY_MASK;

#if(_KEY_SCAN_TYPE == _KEY_SCAN_NORMAL)

    if(!bKey_P54)   ucKeyState    = ucKeyState | _POWER_KEY_MASK;   //Power
    if(!bKey_P56)   ucKeyState    = ucKeyState | _DOWN_KEY_MASK;    //Down
    if(!bKey_P55)   ucKeyState    = ucKeyState | _UP_KEY_MASK;      //Up
    if(!bKey_P57)   ucKeyState    = ucKeyState | _LEFT_KEY_MASK;    //Left
    if(!bKey_P76)   ucKeyState    = ucKeyState | _RIGHT_KEY_MASK;   //Right
    if(!bKey_P34)   ucKeyState    = ucKeyState | _SOURCE_KEY_MASK;  //Source
    if(!bKey_P81)   ucKeyState    = ucKeyState | _MENU_KEY_MASK;    //Menu

#else

    CGetADCValue(&pData[0]);
    CGetADCValue(&pData[3]);

/*  if(_ABS(pData[0], pData[3]) < 3)
    {
        // AD key0
        if     (_ABS(pData[0], bAD0_Key_0) < 3)  ucKeyState = _POWER_KEY_MASK;
        else if(_ABS(pData[0], bAD0_Key_1) < 3)  ucKeyState = _POWER_KEY_MASK;
        else if(_ABS(pData[0], bAD0_Key_2) < 3)  ucKeyState = _POWER_KEY_MASK;
    }
*/  

	ucKeyADValue = pData[0];

    // AD key1
    if(_ABS(pData[0], pData[3]) < 3)
    {
        if     (_ABS(pData[0], bAD1_Key_7) < 3)  ucKeyState = _POWER_KEY_MASK;
        else if(_ABS(pData[0], bAD1_Key_4) < 3)  ucKeyState = _RIGHT_KEY_MASK;
        else if(_ABS(pData[0], bAD1_Key_2) < 3)  ucKeyState = _LEFT_KEY_MASK;
        else if(_ABS(pData[0], bAD1_Key_3) < 3)  ucKeyState = _MENU_KEY_MASK;
		else if(_ABS(pData[0], bAD1_Key_1) < 3)  ucKeyState = _RESET_KEY_MASK;
        else if(_ABS(pData[0], bAD1_Key_5) < 3)  ucKeyState = _UP_KEY_MASK;
		else if(_ABS(pData[0], bAD1_Key_6) < 3)  ucKeyState = _DOWN_KEY_MASK;
        else if(_ABS(pData[0], bAD1_Key_8) < 3)  ucKeyState = _SOURCE_KEY_MASK;
    }

#endif

    if(ucKeyState != _NONE_KEY_MASK)
       CKeyInitial();

    return ucKeyState;
}
Exemplo n.º 2
0
inline unsigned char fuy(const unsigned char *im, const unsigned int idx, const int *noisymap, const unsigned int w, const unsigned int h,
    const float alfa, const float beta, pow_table &pt) {
  //get the pixel and the four closest neighbors (with replication-padding)
  unsigned char pixel = im[idx];
  //up
  int idx_neighbor = idx - w * (idx >= w);
  unsigned char up_val = im[idx_neighbor];
  unsigned char up_noisy = (noisymap[idx_neighbor] >= 0);
  //down
  idx_neighbor = idx + w * (idx < ((h - 1) * w));
  unsigned char down_val = im[idx_neighbor];
  unsigned char down_noisy = (noisymap[idx_neighbor] >= 0);
  //left
  idx_neighbor = idx - ((idx % w) > 0);
  unsigned char left_val = im[idx_neighbor];
  unsigned char left_noisy = (noisymap[idx_neighbor] >= 0);
  //right
  idx_neighbor = idx + ((idx % w) < (w - 1));
  unsigned char right_val = im[idx_neighbor];
  unsigned char right_noisy = (noisymap[idx_neighbor] >= 0);

  //compute the correction
  unsigned char u;
  float S;
  float Fu, u_min = 0.0f, Fu_prec = FLT_MAX;
  float beta_ = beta / 2;
  for (int uu = 0; uu < 256; ++uu) {
    u = (unsigned char) uu;
    Fu = 0.0f;
    S = 0.0f;
    S += (float) (2 - up_noisy) * pt(_ABS(uu - (int) up_val));
    S += (float) (2 - down_noisy) * pt(_ABS(uu - (int) down_val));
    S += (float) (2 - left_noisy) * pt(_ABS(uu - (int) left_val));
    S += (float) (2 - right_noisy) * pt(_ABS(uu - (int) right_val));
    Fu += _ABS((float) u - (float) pixel) + (beta_) * S;
    if (Fu < Fu_prec) {
      u_min = u;
      Fu_prec = Fu;
    }
  }

  unsigned char new_val = (unsigned char) (u_min + 0.5f); //round
  return new_val;
}
Exemplo n.º 3
0
main()
{
	complex	c[NUM_TESTS];

	complex	ans[NUM_TESTS];

	complex	d;

	c[0] = complex(0, 0);		ans[0] = complex(0, 0);
	c[1] = complex(1, 0);		ans[1] = complex(1, 0);
	c[2] = complex(0, 2);		ans[2] = complex(1, 1);
	c[3] = complex(-1, 0);		ans[3] = complex(0, 1);
	c[4] = complex(0, -2);		ans[4] = complex(1, -1);

	for ( int i = 0; i < NUM_TESTS; i++ ) {

		errno = 0;

		d = sqrt(c[i]);

		if ( errno ) {
			cout << "*** test failed *** sqrt("
				<< c[i] << "), errno=" << errno << "\n";
			continue;
		}

		if ( _ABS(real(d) - real(ans[i])) > X_EPS
					||
		     _ABS(imag(d) - imag(ans[i])) > X_EPS ) {
			cout << "*** test failed *** sqrt("
				<< c[i] << ") = " << d << ", correct answer = "
				<< ans[i] << "\n";
		}
		else
			cout << "*** test passed *** sqrt("
				<< c[i] << ") = " << d << "\n";
	}
	return 0;
}
Exemplo n.º 4
0
/**
  * @brief  Digital load handler

  * @param  None

	  @retval None
  */
void Digital_Load_Handler(void *pvParameters)
{
	float current = 0;
	double lstRefVoltage;
	double curtRefVoltage;
	double preferredRefVoltage;

	double coeficient = 0.05;

	bool  lstTrend;
	bool  curtTrend;
	for (;;)
	{
		while (xQueueReceive(Digital_Load_Command, &current, portMAX_DELAY) != pdPASS);
		if (current > 0 && current < 4.1)
		{
      Digital_Load_Unlock();
			preferredRefVoltage = current*Calibration_Data->Refk + Calibration_Data->Refb;
			lstRefVoltage = preferredRefVoltage;
			Set_RefVoltageTo(lstRefVoltage);
			if (current < 0.3)
				vTaskDelay(750 / portTICK_RATE_MS);
			else
				vTaskDelay(500 / portTICK_RATE_MS);
			lstTrend = true;
			coeficient = 0.01;
		}
		for (;;)
		{
			if (current < 0 || current> 4.6)
			{
				Set_RefVoltageTo(0); 
        Digital_Load_Lock();break;
			}
			else
			{
				xSemaphoreTake(USBMeterState_Mutex, portMAX_DELAY);
				curtRefVoltage = current / CurrentMeterData.Current*lstRefVoltage;
				xSemaphoreGive(USBMeterState_Mutex);
				if (current > CurrentMeterData.Current) curtTrend = true;
				else curtTrend = false;
				if (curtRefVoltage != lstRefVoltage)
				{
					if (lstTrend == curtTrend) coeficient = coeficient * 2;
					else coeficient = 0.02;
					coeficient = coeficient > 0.5 ? 0.5 : coeficient;
					coeficient = coeficient < 0.01 ? 0.01 : coeficient;
					curtRefVoltage = (curtRefVoltage - lstRefVoltage)*coeficient + lstRefVoltage;
					//          curtRefVoltage = curtRefVoltage>1.5*preferredRefVoltage+0.1?1.5*preferredRefVoltage+0.1:curtRefVoltage;
					if (_ABS(curtRefVoltage - lstRefVoltage) > 0.00005)
					{
						Set_RefVoltageTo(curtRefVoltage);
						lstRefVoltage = curtRefVoltage;
					}
				}
				lstTrend = curtTrend;
				if (xQueueReceive(Digital_Load_Command, &current, 270) == pdPASS)
				{
					preferredRefVoltage = current*Calibration_Data->Refk + Calibration_Data->Refb;
          if(_ABS(curtRefVoltage - preferredRefVoltage) > 0.02)
					curtRefVoltage = preferredRefVoltage;
					coeficient = 0.01;
					lstRefVoltage = curtRefVoltage;
					Set_RefVoltageTo(curtRefVoltage);
					vTaskDelay(400 / portTICK_RATE_MS);
				}
			}
			CurrentRefVoltage = curtRefVoltage;
		}
	}
}
Exemplo n.º 5
0
Arquivo: popt.c Projeto: OPSF/uClinux
/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
int poptGetNextOpt(poptContext con)
{
    const struct poptOption * opt = NULL;
    int done = 0;

    if (con == NULL)
	return -1;
    while (!done) {
	const char * origOptString = NULL;
	poptCallbackType cb = NULL;
	const void * cbData = NULL;
	const char * longArg = NULL;
	int canstrip = 0;
	int shorty = 0;

	while (!con->os->nextCharArg && con->os->next == con->os->argc
		&& con->os > con->optionStack) {
	    cleanOSE(con->os--);
	}
	if (!con->os->nextCharArg && con->os->next == con->os->argc) {
	    /*@-internalglobs@*/
	    invokeCallbacksPOST(con, con->options);
	    /*@=internalglobs@*/
	    if (con->doExec) return execCommand(con);
	    return -1;
	}

	/* Process next long option */
	if (!con->os->nextCharArg) {
	    char * localOptString, * optString;
	    int thisopt;

	    /*@-sizeoftype@*/
	    if (con->os->argb && PBM_ISSET(con->os->next, con->os->argb)) {
		con->os->next++;
		continue;
	    }
	    /*@=sizeoftype@*/
	    thisopt = con->os->next;
	    if (con->os->argv != NULL)	/* XXX can't happen */
	    origOptString = con->os->argv[con->os->next++];

	    if (origOptString == NULL)	/* XXX can't happen */
		return POPT_ERROR_BADOPT;

	    if (con->restLeftover || *origOptString != '-') {
		if (con->flags & POPT_CONTEXT_POSIXMEHARDER)
		    con->restLeftover = 1;
		if (con->flags & POPT_CONTEXT_ARG_OPTS) {
		    con->os->nextArg = xstrdup(origOptString);
		    return 0;
		}
		if (con->leftovers != NULL)	/* XXX can't happen */
		    con->leftovers[con->numLeftovers++] = origOptString;
		continue;
	    }

	    /* Make a copy we can hack at */
	    localOptString = optString =
		strcpy(alloca(strlen(origOptString) + 1), origOptString);

	    if (optString[0] == '\0')
		return POPT_ERROR_BADOPT;

	    if (optString[1] == '-' && !optString[2]) {
		con->restLeftover = 1;
		continue;
	    } else {
		char *oe;
		int singleDash;

		optString++;
		if (*optString == '-')
		    singleDash = 0, optString++;
		else
		    singleDash = 1;

		/* XXX aliases with arg substitution need "--alias=arg" */
		if (handleAlias(con, optString, '\0', NULL))
		    continue;

		if (handleExec(con, optString, '\0'))
		    continue;

		/* Check for "--long=arg" option. */
		for (oe = optString; *oe && *oe != '='; oe++)
		    {};
		if (*oe == '=') {
		    *oe++ = '\0';
		    /* XXX longArg is mapped back to persistent storage. */
		    longArg = origOptString + (oe - localOptString);
		}

		opt = findOption(con->options, optString, '\0', &cb, &cbData,
				 singleDash);
		if (!opt && !singleDash)
		    return POPT_ERROR_BADOPT;
	    }

	    if (!opt) {
		con->os->nextCharArg = origOptString + 1;
	    } else {
		if (con->os == con->optionStack &&
		   opt->argInfo & POPT_ARGFLAG_STRIP)
		{
		    canstrip = 1;
		    poptStripArg(con, thisopt);
		}
		shorty = 0;
	    }
	}

	/* Process next short option */
	/*@-branchstate@*/		/* FIX: W2DO? */
	if (con->os->nextCharArg) {
	    origOptString = con->os->nextCharArg;

	    con->os->nextCharArg = NULL;

	    if (handleAlias(con, NULL, *origOptString, origOptString + 1))
		continue;

	    if (handleExec(con, NULL, *origOptString)) {
		/* Restore rest of short options for further processing */
		origOptString++;
		if (*origOptString != '\0')
		    con->os->nextCharArg = origOptString;
		continue;
	    }

	    opt = findOption(con->options, NULL, *origOptString, &cb,
			     &cbData, 0);
	    if (!opt)
		return POPT_ERROR_BADOPT;
	    shorty = 1;

	    origOptString++;
	    if (*origOptString != '\0')
		con->os->nextCharArg = origOptString;
	}
	/*@=branchstate@*/

	if (opt == NULL) return POPT_ERROR_BADOPT;	/* XXX can't happen */
	if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) {
	    if (poptSaveInt((int *)opt->arg, opt->argInfo, 1L))
		return POPT_ERROR_BADOPERATION;
	} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) {
	    if (opt->arg) {
		if (poptSaveInt((int *)opt->arg, opt->argInfo, (long)opt->val))
		    return POPT_ERROR_BADOPERATION;
	    }
	} else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
	    con->os->nextArg = _free(con->os->nextArg);
	    /*@-usedef@*/	/* FIX: W2DO? */
	    if (longArg) {
	    /*@=usedef@*/
		longArg = expandNextArg(con, longArg);
		con->os->nextArg = longArg;
	    } else if (con->os->nextCharArg) {
		longArg = expandNextArg(con, con->os->nextCharArg);
		con->os->nextArg = longArg;
		con->os->nextCharArg = NULL;
	    } else {
		while (con->os->next == con->os->argc &&
		       con->os > con->optionStack) {
		    cleanOSE(con->os--);
		}
		if (con->os->next == con->os->argc) {
		    if (!(opt->argInfo & POPT_ARGFLAG_OPTIONAL))
			/*@-compdef@*/	/* FIX: con->os->argv not defined */
			return POPT_ERROR_NOARG;
			/*@=compdef@*/
		    con->os->nextArg = NULL;
		} else {

		    /*
		     * Make sure this isn't part of a short arg or the
		     * result of an alias expansion.
		     */
		    if (con->os == con->optionStack &&
			(opt->argInfo & POPT_ARGFLAG_STRIP) &&
			canstrip) {
			poptStripArg(con, con->os->next);
		    }
		
		    if (con->os->argv != NULL) {	/* XXX can't happen */
			/* XXX watchout: subtle side-effects live here. */
			longArg = con->os->argv[con->os->next++];
			longArg = expandNextArg(con, longArg);
			con->os->nextArg = longArg;
		    }
		}
	    }
	    longArg = NULL;

	    if (opt->arg) {
		switch (opt->argInfo & POPT_ARG_MASK) {
		case POPT_ARG_STRING:
		    /* XXX memory leak, hard to plug */
		    *((const char **) opt->arg) = (con->os->nextArg)
			? xstrdup(con->os->nextArg) : NULL;
		    /*@switchbreak@*/ break;

		case POPT_ARG_INT:
		case POPT_ARG_LONG:
		{   long aLong = 0;
		    char *end;

		    if (con->os->nextArg) {
			aLong = strtol(con->os->nextArg, &end, 0);
			if (!(end && *end == '\0'))
			    return POPT_ERROR_BADNUMBER;
		    }

		    if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
			if (aLong == LONG_MIN || aLong == LONG_MAX)
			    return POPT_ERROR_OVERFLOW;
			if (poptSaveLong((long *)opt->arg, opt->argInfo, aLong))
			    return POPT_ERROR_BADOPERATION;
		    } else {
			if (aLong > INT_MAX || aLong < INT_MIN)
			    return POPT_ERROR_OVERFLOW;
			if (poptSaveInt((int *)opt->arg, opt->argInfo, aLong))
			    return POPT_ERROR_BADOPERATION;
		    }
		}   /*@switchbreak@*/ break;

		case POPT_ARG_FLOAT:
		case POPT_ARG_DOUBLE:
		{   double aDouble = 0.0;
		    char *end;

		    if (con->os->nextArg) {
			/*@-mods@*/
			int saveerrno = errno;
			errno = 0;
			aDouble = strtod(con->os->nextArg, &end);
			if (errno == ERANGE)
			    return POPT_ERROR_OVERFLOW;
			errno = saveerrno;
			/*@=mods@*/
			if (*end != '\0')
			    return POPT_ERROR_BADNUMBER;
		    }

		    if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) {
			*((double *) opt->arg) = aDouble;
		    } else {
#define _ABS(a)	((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a))
			if ((_ABS(aDouble) - FLT_MAX) > DBL_EPSILON)
			    return POPT_ERROR_OVERFLOW;
			if ((FLT_MIN - _ABS(aDouble)) > DBL_EPSILON)
			    return POPT_ERROR_OVERFLOW;
			*((float *) opt->arg) = aDouble;
		    }
		}   /*@switchbreak@*/ break;
		default:
		    fprintf(stdout,
			POPT_("option type (%d) not implemented in popt\n"),
			(opt->argInfo & POPT_ARG_MASK));
		    exit(EXIT_FAILURE);
		    /*@notreached@*/ /*@switchbreak@*/ break;
		}
	    }
	}

	if (cb) {
	    /*@-internalglobs@*/
	    invokeCallbacksOPTION(con, con->options, opt, cbData, shorty);
	    /*@=internalglobs@*/
	} else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL))
	    done = 1;

	if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) {
	    con->finalArgvAlloced += 10;
	    con->finalArgv = realloc(con->finalArgv,
			    sizeof(*con->finalArgv) * con->finalArgvAlloced);
	}

	if (con->finalArgv != NULL)
	{   char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3);
	    if (s != NULL) {	/* XXX can't happen */
		if (opt->longName)
		    sprintf(s, "%s%s",
			((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
			opt->longName);
		else
		    sprintf(s, "-%c", opt->shortName);
		con->finalArgv[con->finalArgvCount++] = s;
	    } else
		con->finalArgv[con->finalArgvCount++] = NULL;
	}

	if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE)
	    /*@-ifempty@*/ ; /*@=ifempty@*/
	else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL)
	    /*@-ifempty@*/ ; /*@=ifempty@*/
	else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
	    if (con->finalArgv != NULL && con->os->nextArg)
	        con->finalArgv[con->finalArgvCount++] =
			/*@-nullpass@*/	/* LCL: con->os->nextArg != NULL */
			xstrdup(con->os->nextArg);
			/*@=nullpass@*/
	}
    }

    return (opt ? opt->val : -1);	/* XXX can't happen */
}
Exemplo n.º 6
0
void MatrixLinearEqSolve(
	float		* const pRes,
	float		** const pSrc,	// 2D array of floats. 4 Eq linear problem is 5x4 matrix, constants in first column.
	const int	nCnt)
{
	int		i, j, k;
	float	f;

#if 0
	/*
		Show the matrix in debug output
	*/
	_RPT1(_CRT_WARN, "LinearEqSolve(%d)\n", nCnt);
	for(i = 0; i < nCnt; ++i)
	{
		_RPT1(_CRT_WARN, "%.8f |", pSrc[i][0]);
		for(j = 1; j <= nCnt; ++j)
			_RPT1(_CRT_WARN, " %.8f", pSrc[i][j]);
		_RPT0(_CRT_WARN, "\n");
	}
#endif

	if(nCnt == 1)
	{
		_ASSERT(pSrc[0][1] != 0);
		pRes[0] = pSrc[0][0] / pSrc[0][1];
		return;
	}

	// Loop backwards in an attempt avoid the need to swap rows
	i = nCnt;
	while(i)
	{
		--i;

		if(pSrc[i][nCnt] != 0)
		{
			// Row i can be used to zero the other rows; let's move it to the bottom
			if(i != (nCnt-1))
			{
				for(j = 0; j <= nCnt; ++j)
				{
					// Swap the two values
					f = pSrc[nCnt-1][j];
					pSrc[nCnt-1][j] = pSrc[i][j];
					pSrc[i][j] = f;
				}
			}

			// Now zero the last columns of the top rows
			for(j = 0; j < (nCnt-1); ++j)
			{
				_ASSERT(pSrc[nCnt-1][nCnt] != 0);
				f = pSrc[j][nCnt] / pSrc[nCnt-1][nCnt];

				// No need to actually calculate a zero for the final column
				for(k = 0; k < nCnt; ++k)
				{
					pSrc[j][k] -= f * pSrc[nCnt-1][k];
				}
			}

			break;
		}
	}

	// Solve the top-left sub matrix
	MatrixLinearEqSolve(pRes, pSrc, nCnt - 1);

	// Now calc the solution for the bottom row
	f = pSrc[nCnt-1][0];
	for(k = 1; k < nCnt; ++k)
	{
		f -= pSrc[nCnt-1][k] * pRes[k-1];
	}
	_ASSERT(pSrc[nCnt-1][nCnt] != 0);
	f /= pSrc[nCnt-1][nCnt];
	pRes[nCnt-1] = f;

#if 0
	{
		float fCnt;

		/*
			Verify that the result is correct
		*/
		fCnt = 0;
		for(i = 1; i <= nCnt; ++i)
			fCnt += pSrc[nCnt-1][i] * pRes[i-1];

		_ASSERT(_ABS(fCnt - pSrc[nCnt-1][0]) < 1e-3);
	}
#endif
}
Exemplo n.º 7
0
void MatrixInverse(
	MATRIX			&mOut,
	const MATRIX	&mIn)
{
	MATRIX	mDummyMatrix;
	double		det_1;
	double		pos, neg, temp;

    /* Calculate the determinant of submatrix A and determine if the
       the matrix is singular as limited by the double precision
       floating-point data representation. */
    pos = neg = 0.0;
    temp =  mIn.f[ 0] * mIn.f[ 5] * mIn.f[10];
    if (temp >= 0.0) pos += temp; else neg += temp;
    temp =  mIn.f[ 4] * mIn.f[ 9] * mIn.f[ 2];
    if (temp >= 0.0) pos += temp; else neg += temp;
    temp =  mIn.f[ 8] * mIn.f[ 1] * mIn.f[ 6];
    if (temp >= 0.0) pos += temp; else neg += temp;
    temp = -mIn.f[ 8] * mIn.f[ 5] * mIn.f[ 2];
    if (temp >= 0.0) pos += temp; else neg += temp;
    temp = -mIn.f[ 4] * mIn.f[ 1] * mIn.f[10];
    if (temp >= 0.0) pos += temp; else neg += temp;
    temp = -mIn.f[ 0] * mIn.f[ 9] * mIn.f[ 6];
    if (temp >= 0.0) pos += temp; else neg += temp;
    det_1 = pos + neg;

    /* Is the submatrix A singular? */
    if ((det_1 == 0.0) || (_ABS(det_1 / (pos - neg)) < 1.0e-15))
	{
        /* Matrix M has no inverse */
        printf("Matrix has no inverse : singular matrix\n");
        return;
    }
    else
	{
        /* Calculate inverse(A) = adj(A) / det(A) */
        det_1 = 1.0 / det_1;
        mDummyMatrix.f[ 0] =   ( mIn.f[ 5] * mIn.f[10] - mIn.f[ 9] * mIn.f[ 6] ) * (float)det_1;
        mDummyMatrix.f[ 1] = - ( mIn.f[ 1] * mIn.f[10] - mIn.f[ 9] * mIn.f[ 2] ) * (float)det_1;
        mDummyMatrix.f[ 2] =   ( mIn.f[ 1] * mIn.f[ 6] - mIn.f[ 5] * mIn.f[ 2] ) * (float)det_1;
        mDummyMatrix.f[ 4] = - ( mIn.f[ 4] * mIn.f[10] - mIn.f[ 8] * mIn.f[ 6] ) * (float)det_1;
        mDummyMatrix.f[ 5] =   ( mIn.f[ 0] * mIn.f[10] - mIn.f[ 8] * mIn.f[ 2] ) * (float)det_1;
        mDummyMatrix.f[ 6] = - ( mIn.f[ 0] * mIn.f[ 6] - mIn.f[ 4] * mIn.f[ 2] ) * (float)det_1;
        mDummyMatrix.f[ 8] =   ( mIn.f[ 4] * mIn.f[ 9] - mIn.f[ 8] * mIn.f[ 5] ) * (float)det_1;
        mDummyMatrix.f[ 9] = - ( mIn.f[ 0] * mIn.f[ 9] - mIn.f[ 8] * mIn.f[ 1] ) * (float)det_1;
        mDummyMatrix.f[10] =   ( mIn.f[ 0] * mIn.f[ 5] - mIn.f[ 4] * mIn.f[ 1] ) * (float)det_1;

        /* Calculate -C * inverse(A) */
        mDummyMatrix.f[12] = - ( mIn.f[12] * mDummyMatrix.f[ 0] + mIn.f[13] * mDummyMatrix.f[ 4] + mIn.f[14] * mDummyMatrix.f[ 8] );
        mDummyMatrix.f[13] = - ( mIn.f[12] * mDummyMatrix.f[ 1] + mIn.f[13] * mDummyMatrix.f[ 5] + mIn.f[14] * mDummyMatrix.f[ 9] );
        mDummyMatrix.f[14] = - ( mIn.f[12] * mDummyMatrix.f[ 2] + mIn.f[13] * mDummyMatrix.f[ 6] + mIn.f[14] * mDummyMatrix.f[10] );

        /* Fill in last row */
        mDummyMatrix.f[ 3] = 0.0f;
		mDummyMatrix.f[ 7] = 0.0f;
		mDummyMatrix.f[11] = 0.0f;
        mDummyMatrix.f[15] = 1.0f;
	}

   	/* Copy contents of dummy matrix in pfMatrix */
	mOut = mDummyMatrix;
}
Exemplo n.º 8
0
main()
{
	complex		d;

	errno = 0;

	d = exp(complex(MAX_EXPONENT+1,1));

	if ( errno != ERANGE )
		cout << "*** test failed *** exp(complex(MAX_EXPONENT+1,1))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)-HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)-HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** exp(complex(MAX_EXPONENT+1,1))) = "
			<< d << ", correct answer = "
			<< complex(HUGE,HUGE) << "\n";

	else
		cout << "*** test passed *** exp(complex(MAX_EXPONENT+1,1))) = "
			<< d << "\n";

	errno = 0;

	d = exp(complex(MAX_EXPONENT+1,5*M_PI/4));

	if ( errno != ERANGE )
		cout << "*** test failed *** exp(complex(MAX_EXPONENT+1,5*M_PI/4))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)+HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)+HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** exp(complex(MAX_EXPONENT+1,5*M_PI/4))) = "
			<< d << ", correct answer = "
			<< complex(-HUGE,-HUGE) << "\n";

	else
		cout << "*** test passed *** exp(complex(MAX_EXPONENT+1,5*M_PI/4))) = "
			<< d << "\n";

	errno = 0;

	d = exp(complex(MIN_EXPONENT-1,0));

	if ( errno != ERANGE )
		cout << "*** test failed *** exp(complex(MIN_EXPONENT+1,0))), errno="
			<< errno << "\n";

	else if ( _ABS(real(d)) > X_EPS
				||
		  _ABS(imag(d)) > X_EPS )
		cout << "*** test failed *** exp(complex(MIN_EXPONENT+1,0))) = "
			<< d << ", correct answer = "
			<< complex(0,0) << "\n";

	else
		cout << "*** test passed *** exp(complex(MIN_EXPONENT+1,0))) = "
			<< d << "\n";

	errno = 0;

	d = exp(complex(0,EXPGOOD+1));

	if ( errno != ERANGE )
		cout << "*** test failed *** exp(complex(0,EXPGOOD+1))), errno="
			<< errno << "\n";

	else if ( _ABS(real(d)) > X_EPS
				||
		  _ABS(imag(d)) > X_EPS )
		cout << "*** test failed *** exp(complex(0,EXPGOOD+1))) = "
			<< d << ", correct answer = "
			<< complex(0,0) << "\n";

	else
		cout << "*** test passed *** exp(complex(0,EXPGOOD+1))) = "
			<< d << "\n";

	errno = 0;

	d = log(complex(0,0));

	if ( errno != EDOM )
		cout << "*** test failed *** log(complex(0,0))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)-HUGE)/HUGE) > X_EPS
				||
		  _ABS(imag(d)) > X_EPS )
		cout << "*** test failed *** log(complex(0,0))) = "
			<< d << ", correct answer = "
			<< complex(HUGE,0) << "\n";

	else
		cout << "*** test passed *** log(complex(0,0))) = "
			<< d << "\n";

	errno = 0;

	d = sinh(complex(MAX_EXPONENT+1,1));

	if ( errno != ERANGE )
		cout << "*** test failed *** sinh(complex(MAX_EXPONENT+1,1))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)-HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)-HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** sinh(complex(MAX_EXPONENT+1,1))) = "
			<< d << ", correct answer = "
			<< complex(HUGE,HUGE) << "\n";

	else
		cout << "*** test passed *** sinh(complex(MAX_EXPONENT+1,1))) = "
			<< d << "\n";

	errno = 0;

	d = sinh(complex(MAX_EXPONENT+1,5*M_PI/4));

	if ( errno != ERANGE )
		cout << "*** test failed *** sinh(complex(MAX_EXPONENT+1,5*M_PI/4))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)+HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)+HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** sinh(complex(MAX_EXPONENT+1,5*M_PI/4))) = "
			<< d << ", correct answer = "
			<< complex(-HUGE,-HUGE) << "\n";

	else
		cout << "*** test passed *** sinh(complex(MAX_EXPONENT+1,5*M_PI/4))) = "
			<< d << "\n";

	errno = 0;

	d = sinh(complex(MIN_EXPONENT-1,1));

	if ( errno != ERANGE )
		cout << "*** test failed *** sinh(complex(MIN_EXPONENT-1,1))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)+HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)-HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** sinh(complex(MIN_EXPONENT-1,1))) = "
			<< d << ", correct answer = "
			<< complex(HUGE,HUGE) << "\n";

	else
		cout << "*** test passed *** sinh(complex(MIN_EXPONENT-1,1))) = "
			<< d << "\n";

	errno = 0;

	d = sinh(complex(MIN_EXPONENT-1,5*M_PI/4));

	if ( errno != ERANGE )
		cout << "*** test failed *** sinh(complex(MIN_EXPONENT-1,5*M_PI/4))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)-HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)+HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** sinh(complex(MIN_EXPONENT-1,5*M_PI/4))) = "
			<< d << ", correct answer = "
			<< complex(-HUGE,-HUGE) << "\n";

	else
		cout << "*** test passed *** sinh(complex(MIN_EXPONENT-1,5*M_PI/4))) = "
			<< d << "\n";

	errno = 0;

	d = sinh(complex(0,SINH_GOOD+1));

	if ( errno != ERANGE )
		cout << "*** test failed *** sinh(complex(0,SINH_GOOD+1))), errno="
			<< errno << "\n";

	else if ( _ABS(real(d)) > X_EPS
				||
		  _ABS(imag(d)) > X_EPS )
		cout << "*** test failed *** sinh(complex(0,SINH_GOOD+1))) = "
			<< d << ", correct answer = "
			<< complex(0,0) << "\n";

	else
		cout << "*** test passed *** sinh(complex(0,SINH_GOOD+1))) = "
			<< d << "\n";

	errno = 0;

	d = cosh(complex(MAX_EXPONENT+1,1));

	if ( errno != ERANGE )
		cout << "*** test failed *** cosh(complex(MAX_EXPONENT+1,1))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)-HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)-HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** cosh(complex(MAX_EXPONENT+1,1))) = "
			<< d << ", correct answer = "
			<< complex(HUGE,HUGE) << "\n";

	else
		cout << "*** test passed *** cosh(complex(MAX_EXPONENT+1,1))) = "
			<< d << "\n";

	errno = 0;

	d = cosh(complex(MAX_EXPONENT+1,5*M_PI/4));

	if ( errno != ERANGE )
		cout << "*** test failed *** cosh(complex(MAX_EXPONENT+1,5*M_PI/4))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)+HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)+HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** cosh(complex(MAX_EXPONENT+1,5*M_PI/4))) = "
			<< d << ", correct answer = "
			<< complex(-HUGE,-HUGE) << "\n";

	else
		cout << "*** test passed *** cosh(complex(MAX_EXPONENT+1,5*M_PI/4))) = "
			<< d << "\n";

	errno = 0;

	d = cosh(complex(MIN_EXPONENT-1,1));

	if ( errno != ERANGE )
		cout << "*** test failed *** cosh(complex(MIN_EXPONENT-1,1))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)-HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)+HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** cosh(complex(MIN_EXPONENT-1,1))) = "
			<< d << ", correct answer = "
			<< complex(HUGE,HUGE) << "\n";

	else
		cout << "*** test passed *** cosh(complex(MIN_EXPONENT-1,1))) = "
			<< d << "\n";

	errno = 0;

	d = cosh(complex(MIN_EXPONENT-1,5*M_PI/4));

	if ( errno != ERANGE )
		cout << "*** test failed *** cosh(complex(MIN_EXPONENT-1,5*M_PI/4))), errno="
			<< errno << "\n";

	else if ( _ABS((real(d)+HUGE)/HUGE) > X_EPS
				||
		  _ABS((imag(d)-HUGE)/HUGE) > X_EPS )
		cout << "*** test failed *** cosh(complex(MIN_EXPONENT-1,5*M_PI/4))) = "
			<< d << ", correct answer = "
			<< complex(-HUGE,-HUGE) << "\n";

	else
		cout << "*** test passed *** cosh(complex(MIN_EXPONENT-1,5*M_PI/4))) = "
			<< d << "\n";

	errno = 0;

	d = cosh(complex(0,SINH_GOOD+1));

	if ( errno != ERANGE )
		cout << "*** test failed *** cosh(complex(0,SINH_GOOD+1))), errno="
			<< errno << "\n";

	else if ( _ABS(real(d)) > X_EPS
				||
		  _ABS(imag(d)) > X_EPS )
		cout << "*** test failed *** cosh(complex(0,SINH_GOOD+1))) = "
			<< d << ", correct answer = "
			<< complex(0,0) << "\n";

	else
		cout << "*** test passed *** cosh(complex(0,SINH_GOOD+1))) = "
			<< d << "\n";
	return 0;
}