LOCAL_C TInt CalcArcsinArccos(TReal& aTrg, TRealX& x, TBool aCos) { // Calculate arcsin (if aCos false) or arccos (if aCos true) of x // and write result to aTrg. // Algorithm (arcsin): // If x>0.5, replace x with Sqrt((1-x)/2) // ( use identity cos(x)=2(cos(x/2))^2-1 ) // Use polynomial approximation for arcsin(x), 0<=x<=0.5 // If original x>0.5, replace result y with pi/2-2y const TRealX One = *(const TRealX*)Onedata; const TRealX Half = *(const TRealX*)Halfdata; const TRealX Pi = *(const TRealX*)Pidata; const TRealX PiBy2 = *(const TRealX*)PiBy2data; TInt sign=x.iSign&1; x.iSign=0; if (x<=One) { TBool big=(x>Half); if (big) { x=One-x; if (x.iExp>1) x.iExp--; TReal temp; Math::Sqrt(temp, (TReal)x); x=temp; } TRealX y; Math::PolyX(y,x*x,12,(const TRealX*)ArcsinCoeffs); y*=x; if (big) { if (y.iExp) y.iExp++; if (aCos) { if (sign) y=Pi-y; } else { y=PiBy2-y; y.iSign=TInt8(sign); } } else { y.iSign=TInt8(sign); if (aCos) y=PiBy2-y; } return y.GetTReal(aTrg); } return KErrArgument; }
EXPORT_C TReal64 __adddf3(TReal64 a1,TReal64 a2) // // Add two doubles // { TRealX x1=a1; TRealX x2=a2; TRealX res; TReal64 trg; x1.Add(res,x2); // need not check error because no underflow and others will not be lost in conversion TInt ret=res.GetTReal(trg); if (ret!=KErrNone) MathException(ret); return(trg); }
EXPORT_C TReal32 __subsf3(TReal32 a1,TReal32 a2) // // Subtract two floats // { TRealX x1=a1; TRealX x2=a2; TRealX res; TReal32 trg; x1.Sub(res,x2); // need not check error because no underflow and others will not be lost in conversion TInt ret=res.GetTReal(trg); if (ret!=KErrNone) MathException(ret); return(trg); }
GLDEF_C TReal64 __subdf3(TReal64 a1,TReal64 a2) // // Subtract two doubles // { TRealX x1=a1; TRealX x2=a2; TRealX res; TReal64 trg; x1.Sub(res,x2); TInt ret=res.GetTReal(trg); if (ret!=KErrNone) MathException(ret); return(trg); }
EXPORT_C TReal64 __divdf3(TReal64 a1,TReal64 a2) // // Divide two doubles // { TRealX x1=a1; TRealX x2=a2; TRealX res; TReal64 trg; TInt ret=x1.Div(res,x2); if (ret==KErrNone) // must check this because if underflow, error is lost in conversion ret=res.GetTReal(trg); if (ret!=KErrNone) MathException(ret); return((TReal64)res); }
EXPORT_C TReal32 __mulsf3(TReal32 a1,TReal32 a2) // // Multiply two floats // { TRealX x1=a1; TRealX x2=a2; TRealX res; TReal32 trg; TInt ret=x1.Mult(res,x2); if (ret==KErrNone) // must check this because if underflow, error is lost in conversion ret=res.GetTReal(trg); if (ret!=KErrNone) MathException(ret); return((TReal32)res); }
GLDEF_C TReal64 __divdf3(TReal64 a1,TReal64 a2) // // Divide two doubles // { TRealX x1=a1; TRealX x2=a2; TRealX res; TReal64 trg; TInt ret=x1.Div(res,x2); if (ret==KErrNone) ret=res.GetTReal(trg); if (ret!=KErrNone) MathException(ret); return((TReal64)res); }
// ----------------------------------------------------------------------------- // CLandmarksEditDialog::SaveFormDataL // // (other items were commented in a header). // ----------------------------------------------------------------------------- // TBool CLandmarksEditDialog::SaveFormDataL() { CEikEdwin* editor = NULL; // Fetch name TBuf<KPosLmMaxTextFieldLength> name; editor = static_cast <CEikEdwin*> (Control(ELandmarkNameField)); editor->GetText(name); // Fetch description HBufC* descBuf = HBufC::NewLC(KPosLmMaxDescriptionLength); TPtr desc = descBuf->Des(); editor = static_cast <CEikEdwin*> (Control(ELandmarkDescField)); editor->GetText(desc); // Fetch existing location TLocality existingLocation; TBool locationExists = (iLandmark->GetPosition(existingLocation) == KErrNone); TRealX floatFieldValue; // Fetch Latitude TReal latitude = existingLocation.Latitude(); if (iIsRealValueEdited[ELatitudeEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkLatitudeField, R_LMREFAPP_LATITUDE_ERROR); floatFieldValue.GetTReal(latitude); } // Fetch Longitude TReal longitude = existingLocation.Longitude(); if (iIsRealValueEdited[ELongitudeEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkLongitudeField, R_LMREFAPP_LONGITUDE_ERROR); floatFieldValue.GetTReal(longitude); } // Fetch Altitude TReal32 altitude = existingLocation.Altitude(); if (iIsRealValueEdited[EAltitudeEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkAltitudeField, R_LMREFAPP_ALTITUDE_ERROR); floatFieldValue.GetTReal(altitude); } // Fetch horizontal accuracy TReal32 horAcc = existingLocation.HorizontalAccuracy(); if (iIsRealValueEdited[EHorizontalAccEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkHorAccField, R_LMREFAPP_HOR_ACC_ERROR); floatFieldValue.GetTReal(horAcc); } // Fetch vertical accuracy TReal32 verAcc = existingLocation.VerticalAccuracy(); if (iIsRealValueEdited[EVerticalAccEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkVerAccField, R_LMREFAPP_VER_ACC_ERROR); floatFieldValue.GetTReal(verAcc); } // Fetch Coverage Radius TReal32 radius; TInt radiusExists = (iLandmark->GetCoverageRadius(radius) == KErrNone); if (iIsRealValueEdited[ERadiusEditor] || !radiusExists) { FetchFloatL(floatFieldValue, ELandmarkRadiusField, R_LMREFAPP_RADIUS_ERROR); floatFieldValue.GetTReal(radius); } // Fetch street TBuf<KPosLmMaxTextFieldLength> street; editor = static_cast <CEikEdwin*> (Control(ELandmarkStreetField)); editor->GetText(street); // Fetch postal code TBuf<KPosLmMaxTextFieldLength> postalCode; editor = static_cast <CEikEdwin*> (Control(ELandmarkPostalField)); editor->GetText(postalCode); // Fetch city TBuf<KPosLmMaxTextFieldLength> city; editor = static_cast <CEikEdwin*> (Control(ELandmarkCityField)); editor->GetText(city); // Fetch country TBuf<KPosLmMaxTextFieldLength> country; editor = static_cast <CEikEdwin*> (Control(ELandmarkCountryField)); editor->GetText(country); // Update category iLandmark->RemoveLandmarkAttributes(CPosLandmark::ECategoryInfo); for (TInt i = 0; i < iCategoryIds.Count(); i++) { iLandmark->AddCategoryL(iCategoryIds[i]); } // Check that at least some data is entered if (!name.Length() && !desc.Length() && !street.Length() && !city.Length() && !country.Length() && !postalCode.Length() && !iCategoryIds.Count() && Math::IsNaN(latitude) && Math::IsNaN(longitude) && Math::IsNaN(altitude) && Math::IsNaN(radius) && Math::IsNaN(horAcc) && Math::IsNaN(verAcc)) { NotifyErrorToUserL(R_LMREFAPP_EMPTY_LANDMARK); } // Update name iLandmark->SetLandmarkNameL(name); // Update description iLandmark->SetLandmarkDescriptionL(desc); CleanupStack::PopAndDestroy(descBuf); // Update coverage radius if (!Math::IsNaN(radius) && radius < 0) { NotifyErrorToUserL(R_LMREFAPP_RADIUS_ERROR); } iLandmark->SetCoverageRadius(radius); // Update street iLandmark->SetPositionFieldL(EPositionFieldStreet, street); // Update postal code iLandmark->SetPositionFieldL(EPositionFieldPostalCode, postalCode); // Update city iLandmark->SetPositionFieldL(EPositionFieldCity, city); // Update country iLandmark->SetPositionFieldL(EPositionFieldCountry, country); // Update location. There are some rules specified by TLocality and // TCoordinate how to update a location. These rules are taken into // account below when validating the location data. if (Math::IsNaN(latitude) && Math::IsNaN(longitude)) { // If lat long are undefined, then alt and hAcc // must be undefined if (!Math::IsNaN(horAcc)) { NotifyErrorToUserL(R_LMREFAPP_HACC_LAT_LONG_ERROR); } else if (!Math::IsNaN(altitude)) { NotifyErrorToUserL(R_LMREFAPP_ALT_LAT_LONG_ERROR); } else if (!Math::IsNaN(verAcc)) { NotifyErrorToUserL(R_LMREFAPP_VACC_ALT_ERROR); } else { // None position fields are set, Remove position info. iLandmark->RemoveLandmarkAttributes(CPosLandmark::EPosition); } } else if (!Math::IsNaN(latitude) && !Math::IsNaN(longitude)) { // If lat long are defined, hAcc must be positive if defined if (!Math::IsNaN(horAcc) && horAcc < 0) { NotifyErrorToUserL(R_LMREFAPP_HOR_ACC_ERROR); } // if altitude is undefined, then vertical accuracy // must be undefined if (Math::IsNaN(altitude) && !Math::IsNaN(verAcc)) { NotifyErrorToUserL(R_LMREFAPP_VACC_ALT_ERROR); } // vertical accuracy must be positive if defined if (!Math::IsNaN(verAcc) && verAcc < 0) { NotifyErrorToUserL(R_LMREFAPP_VER_ACC_ERROR); } // We are allowed to set the new locality TCoordinate coordinate(latitude, longitude, altitude); TLocality newLocation(coordinate, horAcc, verAcc); iLandmark->SetPositionL(newLocation); } else { // Inform user that no valid lat/long has been entered NotifyErrorToUserL(R_LMREFAPP_LAT_LONG_ERROR); } iEdited = ETrue; return ETrue; }