bool CXMesh::PickPoly(D3DXVECTOR3* PickRayOrig, D3DXVECTOR3* PickRayDir) { if(!m_BlendedMesh) return false; HRESULT res; DWORD FvfSize = D3DXGetFVFVertexSize(m_BlendedMesh->GetFVF()); DWORD NumVertices = m_BlendedMesh->GetNumVertices(); DWORD NumFaces = m_BlendedMesh->GetNumFaces(); // lock vertex buffer BYTE* Points = NULL; res = m_BlendedMesh->LockVertexBufferUni(D3DLOCK_READONLY, &Points); if (FAILED(res)) return false; // lock index buffer WORD* Indices; res = m_BlendedMesh->LockIndexBufferUni(D3DLOCK_READONLY, &Indices); if (FAILED(res)) { m_BlendedMesh->UnlockVertexBuffer(); return false; } bool Found = false; D3DXVECTOR3 Intersection; for(DWORD i=0; i<NumFaces; i++) { WORD i1, i2, i3; i1 = Indices[3*i+0]; i2 = Indices[3*i+1]; i3 = Indices[3*i+2]; D3DXVECTOR3 v0 = *(D3DXVECTOR3*)(Points + Indices[3*i+0] * FvfSize); D3DXVECTOR3 v1 = *(D3DXVECTOR3*)(Points + Indices[3*i+1] * FvfSize); D3DXVECTOR3 v2 = *(D3DXVECTOR3*)(Points + Indices[3*i+2] * FvfSize); if(_isnan(v0.x)) continue; Found = C3DUtils::IntersectTriangle(*PickRayOrig, *PickRayDir, v0, v1, v2, &Intersection.x, &Intersection.y, &Intersection.z) != FALSE; if(Found) break; } m_BlendedMesh->UnlockVertexBuffer(); m_BlendedMesh->UnlockIndexBuffer(); return Found; }
void Rotator::rotate_to(float new_target) { assert(!_isnan(new_target) && _finite(new_target)); assert(_accel_current > 0); assert(_accel_stop > 0); new_target = fmodf(new_target, PI2); if( new_target < 0 ) new_target += PI2; if( new_target == _rCurrent && RS_STOPPED == _state ) return; _angle_target = new_target; _state = RS_GETTING_ANGLE; }
/* Function: rtIsNaN ================================================== * Abstract: * Test if value is not a number */ boolean_T rtIsNaN(real_T value) { #if defined(_MSC_VER) && (_MSC_VER <= 1200) return _isnan(value)? TRUE:FALSE; #else return (value!=value)? 1U:0U; #endif }
/* Function: rtIsNaNF ================================================= * Abstract: * Test if single-precision value is not a number */ boolean_T rtIsNaNF(real32_T value) { #if defined(_MSC_VER) && (_MSC_VER <= 1200) return _isnan((real_T)value)? true:false; #else return (value!=value)? 1U:0U; #endif }
/** * Determine if target is not a number * * @param theNumber target number * @return true if target represents the "not a number" value */ static bool isNaN(double theNumber) { #if defined(_MSC_VER) return _isnan(theNumber) != 0; #elif defined(XALAN_POSIX2_AVAILABLE) && !defined(CYGWIN) && !defined(MINGW) #if defined(XALAN_NO_STD_NAMESPACE) return isnam(theNumber) != 0; #else return std::isnan(theNumber) != 0; #endif #else return s_NaN == theNumber; #endif }
/* Test if single-precision value is not a number */ boolean_T rtIsNaNF(real32_T value) { #if defined(_MSC_VER) && (_MSC_VER <= 1200) /* For MSVC 6.0, use a compiler specific comparison function */ return (boolean_T)(_isnan((real_T)value)? 1U:0U); #else return (boolean_T)(((value!=value) ? 1U : 0U)); #endif }
float Lapidem_Math::AngleBetweenVectors( tVector2D _v1, tVector2D _v2 ) { float fDot( DotProduct( _v1, _v2 ) ); float fLength( Vector2DLength( _v1 ) * Vector2DLength( _v2 ) ); if( 0.0f == fLength ) return 0.0f; float fAngle( acos( fDot / fLength ) ); if( _isnan( fAngle ) ) return 0.0f; return fAngle; }
int __cdecl main(int argc, char **argv) { double zero = 0.0; double PosInf = 1.0 / zero; double NaN = 0.0 / zero; // Force 'value' to be converted to a double to avoid // using the internal precision of the FPU for comparisons. volatile double value; if (PAL_Initialize(argc, argv) != 0) { return FAIL; } /* Test overflows give PosInf */ value = exp(800.0); if (value != PosInf) { Fail( "exp(%g) returned %g when it should have returned %g\n", 800.0, value, PosInf); } value = exp(PosInf); if (value != PosInf) { Fail( "exp(%g) returned %g when it should have returned %g\n", PosInf, value, PosInf); } /* Test underflows give 0 */ value = exp(-800); if (value != 0) { Fail( "exp(%g) returned %g when it should have returned %g\n", -800.0, value, 0.0); } /* Test that a NaN as input gives a NaN */ value = exp(NaN); if (_isnan(value) == 0) { Fail( "exp( NaN ) returned %g when it should have returned NaN\n", value); } PAL_Terminate(); return PASS; }
/* * C3Initialize: Reads data stored in the calibrator. This command should be called * once, after C3Open. */ long C3Initialize( void ) { short i; unsigned char data[128]; float tmpFloat; long(err); double time; C3GetEEPromByte( (char)0, &(data[0])); // dummy read to reset EEPROM for (i=0; i < 128 ; i++) // read entire EEPROM { if ( (err = C3GetEEPromByte( (char)i, &(data[i]))) != 0 ) return(err); } // Store the eeprom structure SIConvertToLong( (char *)&(data[ EEP_SERIALNUMBER ]), (long *)&(eepStruct.sn)); for (i=0; i<9; i++) { SIConvertToFloat( (char *)&(data[ EEP_MATRIX + ( (int)i * sizeof(float)) ]), (float *)&tmpFloat ); eepStruct.matrix[i] = (double)tmpFloat; } SIConvertToWord( (char *)&(data[ EEP_MEASUREMENT_RES ]), (short *)&(eepStruct.resolution )); SIConvertToWord( (char *)&(data[ EEP_MONITOR_FREQUENCY ]), (short *)&(eepStruct.freqHz)); SIConvertToWord( (char *)&(data[ EEP_RED_FIELDCOUNT ]), (short *)&(eepStruct.Rfield)); SIConvertToWord( (char *)&(data[ EEP_GREEN_FIELDCOUNT ]), (short *)&(eepStruct.Gfield)); SIConvertToWord( (char *)&(data[ EEP_BLUE_FIELDCOUNT ]), (short *)&(eepStruct.Bfield)); SIConvertToLong( (char *)&(data[ EEP_CALIBRATION_DATE ]), (long *)&(eepStruct.calDate)); SIConvertToWord( (char *)&(data[ EEP_EEPROM_VERSION ]), (short *)&(eepStruct.version)); // test for valid EEPROM data // if(eepStruct.version >2) return (-1); if(_isnan(eepStruct.matrix[0])) return(-1); c3info.sensorIntegration[0] = (long) ((( 1e11 / ( (double)eepStruct.freqHz * (double)eepStruct.resolution )) * (double) eepStruct.Rfield ) +0.5 ); c3info.sensorIntegration[1] = (long) ((( 1e11 / ( (double)eepStruct.freqHz * (double)eepStruct.resolution )) * (double) eepStruct.Gfield ) +0.5 ); c3info.sensorIntegration[2] = (long) ((( 1e11 / ( (double)eepStruct.freqHz * (double)eepStruct.resolution )) * (double) eepStruct.Bfield ) +0.5 ); c3info.monitorIntegration[0] = c3info.sensorIntegration[0]; c3info.monitorIntegration[1] = c3info.sensorIntegration[1]; c3info.monitorIntegration[2] = c3info.sensorIntegration[2]; time = (double)c3info.monitorIntegration[0] * (double)eepStruct.resolution * 1e-9; C3SetSensorIntegration(time); return(0); }
void checkZeroFinite(const double tmp) throw(std::range_error) { if ((tmp == 0.0) || (! _finite(tmp))) { if (tmp == 0.0) { printf("ERROR: we have encountered a zero!\n"); } else if(_isnan(tmp)) { printf("ERROR: we have encountered a nan!\n"); } else if (_fpclass(tmp) == _FPCLASS_PINF) { printf("ERROR: we have encountered a pos inf!\n"); } else { printf("ERROR: we have encountered a neg inf!\n"); } char sbuf[64]; sprintf(sbuf, "checkZeroFinite: zero or indef exceeded: %g\n", tmp); throw std::range_error(sbuf); } }
/////////////////////////////////////////////////////////////// // // CSpatialDatabaseImpl::IsValidSphere // // Is the sphere valid for use in this class // /////////////////////////////////////////////////////////////// bool CSpatialDatabaseImpl::IsValidSphere ( const CSphere& sphere ) { // Check for nan if ( _isnan ( sphere.fRadius + sphere.vecPosition.fX + sphere.vecPosition.fY + sphere.vecPosition.fZ ) ) return false; // Check radius within limits if ( sphere.fRadius < -10000 || sphere.fRadius > 10000 ) return false; // Check position within limits float fDistSquared2D = sphere.vecPosition.fX * sphere.vecPosition.fX + sphere.vecPosition.fY * sphere.vecPosition.fY; if ( fDistSquared2D > 10000 * 10000 ) return false; return true; }
double xyVectorToDiangle(double x, double y) { double diangle; if (y >= 0) diangle = (x >= 0 ? y/(x+y) : 1-x/(-x+y)); else diangle = (x < 0 ? 2-y/(-x-y) : 3+x/(x-y)); #ifdef _MSC_VER if ( _isnan(diangle) ) #else if (std::isnan(diangle) ) // Windows platform problem: error C3861: 'isnan': identifier not found #endif { std::cout << "numeric::xyVectorToDiangle() error (x,y)= ("<< x << " , " << y << " ) and diangle=" << diangle << "\n"; assert(0); } return diangle; }
ublas::matrix<double> TOutline::createMatrixForFit(double crX0, double crY0, double crRadius) { ublas::matrix<double> data(2,nPoints); //double ** data = new2D(2, nPoints, 0.0); nPointsMinusCR = 0; for (int i=0; i < nPoints; ++i) { //drop points from near cornea reflection if(_isnan(crRadius) || ((xValues[i] - crX0)*(xValues[i] - crX0) + (yValues[i] - crY0)*(yValues[i] - crY0) > crRadius*crRadius)) { data(0,nPointsMinusCR) = (double) xValues[i]; data(1,nPointsMinusCR++) = (double) yValues[i]; } } return data; }
double bcf_pair_freq(const bcf1_t *b0, const bcf1_t *b1, double f[4]) { const bcf1_t *b[2]; int i, j, n_smpl; double *pdg[2], flast[4], r, f0[2]; // initialize others if (b0->n_smpl != b1->n_smpl) return -1; // different number of samples n_smpl = b0->n_smpl; b[0] = b0; b[1] = b1; f[0] = f[1] = f[2] = f[3] = -1.; if (b[0]->n_alleles < 2 || b[1]->n_alleles < 2) return -1; // one allele only pdg[0] = get_pdg3(b0); pdg[1] = get_pdg3(b1); if (pdg[0] == 0 || pdg[1] == 0) { free(pdg[0]); free(pdg[1]); return -1; } // set the initial value f0[0] = est_freq(n_smpl, pdg[0]); f0[1] = est_freq(n_smpl, pdg[1]); f[0] = (1 - f0[0]) * (1 - f0[1]); f[3] = f0[0] * f0[1]; f[1] = (1 - f0[0]) * f0[1]; f[2] = f0[0] * (1 - f0[1]); // iteration for (j = 0; j < ITER_MAX; ++j) { double eps = 0; memcpy(flast, f, 4 * sizeof(double)); pair_freq_iter(n_smpl, pdg, f); for (i = 0; i < 4; ++i) { double x = fabs(f[i] - flast[i]); if (x > eps) eps = x; } if (eps < EPS) break; } // free free(pdg[0]); free(pdg[1]); { // calculate r^2 double p[2], q[2], D; p[0] = f[0] + f[1]; q[0] = 1 - p[0]; p[1] = f[0] + f[2]; q[1] = 1 - p[1]; D = f[0] * f[3] - f[1] * f[2]; r = sqrt(D * D / (p[0] * p[1] * q[0] * q[1])); // printf("R(%lf,%lf,%lf,%lf)=%lf\n", f[0], f[1], f[2], f[3], r); if (_isnan(r)) r = -1.; } return r; }
double AngleBetweenVectors(CVector3 Vector1, CVector3 Vector2) { // Get the dot product of the vectors float dotProduct = Dot(Vector1, Vector2); // Get the product of both of the vectors magnitudes float vectorsMagnitude = Magnitude(Vector1) * Magnitude(Vector2) ; // Get the angle in radians between the 2 vectors double angle = acos( dotProduct / vectorsMagnitude ); // Here we make sure that the angle is not a -1.#IND0000000 number, which means indefinate if(_isnan(angle)) return 0; // Return the angle in radians return( angle ); }
void MovimentadorBracoEsquerdo::mover(irr::scene::IAnimatedMeshSceneNode * node,tipos::Esqueleto esqueleto) { std::string ombro_esquerdo_bone = "UpArm_L"; std::string braco_esquerdo_bone = "LoArm_L"; std::string mao_esquerda_bone = "Index_L"; float anguloOmbroEsquerdo = getAnguloBraco(esqueleto.ombro_esquerdo,esqueleto.cotovelo_esquerdo); setarAnguloBone(node,ombro_esquerdo_bone,-anguloOmbroEsquerdo); float anguloMaoEsquerda = CalculosUteis::anguloEntrePontos(esqueleto.cotovelo_esquerdo,esqueleto.ombro_esquerdo,esqueleto.mao_esquerda); if(esqueleto.cotovelo_esquerdo.y < esqueleto.mao_esquerda.y) anguloMaoEsquerda = - anguloMaoEsquerda; if(!_isnan(anguloMaoEsquerda)) setarAnguloBone(node,braco_esquerdo_bone,anguloMaoEsquerda); IBoneSceneNode * mao = node->getJointNode(mao_esquerda_bone.c_str()); pos = Vetor( mao->getAbsolutePosition().X, mao->getAbsolutePosition().Y, mao->getAbsolutePosition().Z); //teste /* bool tem = false; for(int i=0;i<marcadores.size();i++) { if(marcadores[i]->pontoDentroMarcador(pos) && i!=indiceAnterior) { if(!cronometro.iniciado()) { cronometro.iniciarContagem(); } tem = true; indiceAtual = i; } } if(!tem) { cronometro.pararContagem(); } */ }
static TCHAR * print_sign_float(double val, int w, int frac) { static int idx; static TCHAR buf[8][FIELDW]; // up to 8 simultaneous numbers TCHAR *p = buf[idx = (idx+1)&7]; if (_isnan(val) || !_finite(val)) { _sntprintf(p, FIELDW, _T("%.*s"), w, _T("overflow")); } else { int printed = _sntprintf(p, FIELDW, _T("%+.*f"), frac, val); if (printed > w || printed < 0) { _sntprintf(p, FIELDW, _T("%+.*e"), frac, val); } } return p; }
//Compute daily development rate for table lookup double CTranosemaEquations::ComputeRate(size_t s, double T)const { ASSERT(s >= 0 && s < NB_STAGES); //reltive developement double Rt = 0; switch (s) { case EGG: case PUPA: Rt = Equation1(s, T); break; case ADULT: Rt = Equation2(s, T); break; default: ASSERT(false); } _ASSERTE(!_isnan(Rt) && _finite(Rt)); ASSERT(Rt >= 0); return Rt; }
int main (void) { int i; if (_isinf(s_inf()) && _isinf(-s_inf())) printf("_isinf() test successful.\n"); else printf("_isinf() test failed.\n"); for (i = 0; i < 256; ++i) { if (_isnan(s_nan(i)) != 1) { printf("_isnan() test failed.\n"); return 1; } } printf("_isnan() test successful.\n"); return 0; }
// Find the angle between 2 vectors float AngleBetweenVectors(tVector2D v1, tVector2D v2) { // Dot product float fDot = DotProduct(v1, v2); // Length of those vectors float fLength = Vector2DLength(v1) * Vector2DLength(v2); // Make sure we don't get a divide by zero error. if (fLength == 0.0f) return 0.0f; // Calculate the angle between the two vectors float fAngle = acos( fDot / fLength ); // Make sure the number is not indefinite. Shows up as -1.#IND00000. Not a number. if (_isnan(fAngle)) return 0.0f; // Return the angle. return fAngle; }
// Compute the change in likelihood (Delta) if node UID joins community CID. double TAGMFit::SeekJoin(const int& UID, const int& CID) { IAssert(! CIDNSetV[CID].IsKey(UID)); double Delta = 0.0; TUNGraph::TNodeI NI = G->GetNI(UID); int NbhsInC = 0; for (int e = 0; e < NI.GetDeg(); e++) { const int VID = NI.GetNbrNId(e); if (! NIDComVH.GetDat(VID).IsKey(CID)) { continue; } TIntPr SrcDstNIDPr(TMath::Mn(UID,VID), TMath::Mx(UID,VID)); TIntSet& JointCom = EdgeComVH.GetDat(SrcDstNIDPr); double CurPuv, NewPuv, LambdaSum = SelectLambdaSum(JointCom); CurPuv = 1 - exp(- LambdaSum); if (JointCom.Len() == 0) { CurPuv = PNoCom; } NewPuv = 1 - exp(- LambdaSum - LambdaV[CID]); Delta += (log(NewPuv) - log(CurPuv)); IAssert(!_isnan(Delta)); NbhsInC++; } Delta -= LambdaV[CID] * (CIDNSetV[CID].Len() - NbhsInC); return Delta; }
///////////////////////////////////////////////// // Epidemiological modeling and model fitting void TEpidemModel::RunModel(const TFltV& StartValV, const double& StartT, const double& StopT, const int& NSteps, TVec<TFltV>& OutValV) { TFltV ValV(StartValV), dydx(StartValV.Len()), ValV2(StartValV.Len()); OutValV.Clr(false); for (int v = 0; v < StartValV.Len(); v++) { OutValV.Add(); OutValV[v].Clr(false); OutValV[v].Add(StartValV[v]); } const double h = (StopT-StartT) / NSteps; double x = StartT; for (int k = 0; k < NSteps; k++) { GetDerivs(x, ValV, dydx); RungeKutta(ValV, dydx, x, h, ValV2); for (int v = 0; v < ValV2.Len(); v++) { double X = ValV2[v]; if (X < 0 || _isnan(X) || !_finite(X)) { X = 0; } OutValV[v].Add(X); } ValV = ValV2; x += h; } }
//--------------------------------------------------------------------------- void TPolFuncFrame::SetPoint(const TGraphElem *Elem, int X, int Y) { if(const TPolFunc *Func = dynamic_cast<const TPolFunc*>(Elem)) { TTraceType TraceType; switch(ComboBox1->ItemIndex) { case 0: TraceType = ttTrace; break; case 1: TraceType = ttIntersection; break; case 2: TraceType = ttXAxis; break; case 3: TraceType = ttYAxis; break; case 4: TraceType = ttExtremeX; break; case 5: TraceType = ttExtremeY; break; } double t = TraceFunction(Func, TraceType, X, Y, Form1->Data, Form1->Draw); if(_isnan(t)) Edit1->Text = ""; else Edit1->Text = RoundToStr(t, ComboBox1->ItemIndex == 0 ? Property.RoundTo : std::max(8, Property.RoundTo)); } }
/* Returns 0 if the bitpattern of the \a value argument is not a valid floating point number, otherwise returns non-zero. Note that on some systems, this method will always return 0 (i.e. false positives). */ int coin_isnan(double value) { #ifdef HAVE_ISNAN return isnan(value); #elif defined(HAVE__ISNAN) return _isnan(value); #elif defined(HAVE_FPCLASS) if (fpclass(value) == FP_SNAN) { return 1; } if (fpclass(value) == FP_QNAN) { return 1; } return 0; #elif defined(HAVE__FPCLASS) if (_fpclass(value) == _FPCLASS_SNAN) { return 1; } if (_fpclass(value) == _FPCLASS_QNAN) { return 1; } return 0; #else /* FIXME: it might be possible to investigate the fp bits and decide in a portable manner whether or not they represent a NaN. A groups.google.com search turned up inconclusive. 20030919 mortene. */ return 0; #endif }
void AirframeClass::YawIt(float betcmd, float dt) { // JB 010714 mult by the momentum beta = Math.FLTust(betcmd ,ty02 * auxaeroData->yawMomentum,dt,oldy03); if(beta < -180.0F) { oldy03[0] += 360.0F; oldy03[1] += 360.0F; oldy03[2] += 360.0F; oldy03[3] += 360.0F; } else if(beta > 180.0F) { oldy03[0] -= 360.0F; oldy03[1] -= 360.0F; oldy03[2] -= 360.0F; oldy03[3] -= 360.0F; } ShiAssert(!_isnan(beta)); }
int check_result(double src, double ref, double test, eps_t* thres) { double diff; double error; diff=fabs(ref-test); if(ref==0) error=diff; else error=diff/fabs(ref); if (_isnan(error) || _isinf(error)) return 1; //warning if(error>=thres->warn && error<thres->fail) { return 1; //warning }else if (error >= thres->fail) { printf("error=%12.5E src=%12.5E ref=%12.5E\t test=%12.5E\n", error, src, ref, test); return 2; //error }else{ return 0; //pass } }
void FX_PlayEffect( const char *file, vec3_t org, vec3_t fwd, int vol, int rad ) { #ifdef __FXCHECKER if (_isnan(org[0]) || _isnan(org[1]) || _isnan(org[2])) { assert(0); } if (_isnan(fwd[0]) || _isnan(fwd[1]) || _isnan(fwd[2])) { assert(0); } if (fabs(fwd[0]) < 0.1 && fabs(fwd[1]) < 0.1 && fabs(fwd[2]) < 0.1) { assert(0); } #endif // __FXCHECKER theFxScheduler.PlayEffect(file, org, fwd, vol, rad); }
void FX_PlayEffectID( int id, vec3_t org, vec3_t fwd, int vol, int rad, qboolean isPortal ) { #ifdef __FXCHECKER if (_isnan(org[0]) || _isnan(org[1]) || _isnan(org[2])) { assert(0); } if (_isnan(fwd[0]) || _isnan(fwd[1]) || _isnan(fwd[2])) { assert(0); } if (fabs(fwd[0]) < 0.1 && fabs(fwd[1]) < 0.1 && fabs(fwd[2]) < 0.1) { assert(0); } #endif // __FXCHECKER theFxScheduler.PlayEffect(id, org, fwd, vol, rad, !!isPortal ); }
bool FdoFgfCurveString::GetIsClosed() const { // Get 1st and last position FdoPtr<FdoIDirectPosition> startPos = this->GetStartPosition(); FdoPtr<FdoIDirectPosition> endPos = this->GetEndPosition(); // TODO: the curve isn't really closed if all ordinates are NaN, but rather than // fixing it here, a more general validity tests for the whole line should be done. #ifdef _WIN32 bool isClosed = ( ((_isnan(startPos->GetX()) && _isnan(endPos->GetX())) || startPos->GetX() == endPos->GetX()) && ((_isnan(startPos->GetY()) && _isnan(endPos->GetY())) || startPos->GetY() == endPos->GetY()) && ((_isnan(startPos->GetZ()) && _isnan(endPos->GetZ())) || startPos->GetZ() == endPos->GetZ()) ); #else bool isClosed = ( ((isnan(startPos->GetX()) && isnan(endPos->GetX())) || startPos->GetX() == endPos->GetX()) && ((isnan(startPos->GetY()) && isnan(endPos->GetY())) || startPos->GetY() == endPos->GetY()) && ((isnan(startPos->GetZ()) && isnan(endPos->GetZ())) || startPos->GetZ() == endPos->GetZ()) ); #endif return isClosed; }
int isnan(double a) { return(_isnan(a)); }