Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Internal / FloatUtil.cs / 1305600 / FloatUtil.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: FloatUtil.cs // // Description: This file contains the implementation of FloatUtil, which // provides "fuzzy" comparison functionality for floats and // float-based classes and structs in our code. // // History: // 04/28/2003 : [....] - Created this header // 05/20/2003 : [....] - Move to Shared. // //--------------------------------------------------------------------------- using System; namespace MS.Internal { internal static class FloatUtil { internal static float FLT_EPSILON = 1.192092896e-07F; internal static float FLT_MAX_PRECISION = 0xffffff; internal static float INVERSE_FLT_MAX_PRECISION = 1.0F / FLT_MAX_PRECISION; ////// AreClose /// public static bool AreClose(float a, float b) { if(a == b) return true; // This computes (|a-b| / (|a| + |b| + 10.0f)) < FLT_EPSILON float eps = ((float)Math.Abs(a) + (float)Math.Abs(b) + 10.0f) * FLT_EPSILON; float delta = a - b; return(-eps < delta) && (eps > delta); } ////// IsOne /// public static bool IsOne(float a) { return (float)Math.Abs(a-1.0f) < 10.0f * FLT_EPSILON; } ////// IsZero /// public static bool IsZero(float a) { return (float)Math.Abs(a) < 10.0f * FLT_EPSILON; } ////// IsCloseToDivideByZero /// public static bool IsCloseToDivideByZero(float numerator, float denominator) { // When updating this, please also update code in Arithmetic.h return Math.Abs(denominator) <= Math.Abs(numerator) * INVERSE_FLT_MAX_PRECISION; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: FloatUtil.cs // // Description: This file contains the implementation of FloatUtil, which // provides "fuzzy" comparison functionality for floats and // float-based classes and structs in our code. // // History: // 04/28/2003 : [....] - Created this header // 05/20/2003 : [....] - Move to Shared. // //--------------------------------------------------------------------------- using System; namespace MS.Internal { internal static class FloatUtil { internal static float FLT_EPSILON = 1.192092896e-07F; internal static float FLT_MAX_PRECISION = 0xffffff; internal static float INVERSE_FLT_MAX_PRECISION = 1.0F / FLT_MAX_PRECISION; ////// AreClose /// public static bool AreClose(float a, float b) { if(a == b) return true; // This computes (|a-b| / (|a| + |b| + 10.0f)) < FLT_EPSILON float eps = ((float)Math.Abs(a) + (float)Math.Abs(b) + 10.0f) * FLT_EPSILON; float delta = a - b; return(-eps < delta) && (eps > delta); } ////// IsOne /// public static bool IsOne(float a) { return (float)Math.Abs(a-1.0f) < 10.0f * FLT_EPSILON; } ////// IsZero /// public static bool IsZero(float a) { return (float)Math.Abs(a) < 10.0f * FLT_EPSILON; } ////// IsCloseToDivideByZero /// public static bool IsCloseToDivideByZero(float numerator, float denominator) { // When updating this, please also update code in Arithmetic.h return Math.Abs(denominator) <= Math.Abs(numerator) * INVERSE_FLT_MAX_PRECISION; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SpecialNameAttribute.cs
- DataServiceQuery.cs
- Triplet.cs
- PartialToken.cs
- SignatureDescription.cs
- Imaging.cs
- XmlValidatingReader.cs
- SplashScreenNativeMethods.cs
- ThicknessAnimation.cs
- ArrayConverter.cs
- Bidi.cs
- DataGridViewLinkColumn.cs
- WSDualHttpSecurityMode.cs
- StorageModelBuildProvider.cs
- CacheMode.cs
- HtmlInputImage.cs
- Point.cs
- CompiledQuery.cs
- ReachFixedDocumentSerializer.cs
- XmlnsPrefixAttribute.cs
- unsafenativemethodsother.cs
- RtType.cs
- KeyPullup.cs
- OdbcErrorCollection.cs
- OperationFormatStyle.cs
- LightweightEntityWrapper.cs
- TextServicesContext.cs
- wgx_sdk_version.cs
- ObjectDataSourceWizardForm.cs
- WindowsEditBoxRange.cs
- CorrelationManager.cs
- StylusOverProperty.cs
- LinkGrep.cs
- SafeLibraryHandle.cs
- SettingsPropertyNotFoundException.cs
- MenuBindingsEditor.cs
- NullReferenceException.cs
- DataServiceQueryContinuation.cs
- SystemColors.cs
- FixedSOMPageConstructor.cs
- RoutedCommand.cs
- TextLineBreak.cs
- IDReferencePropertyAttribute.cs
- MethodBody.cs
- BroadcastEventHelper.cs
- TimeSpanConverter.cs
- DatatypeImplementation.cs
- CommandID.cs
- ComponentEditorPage.cs
- ScriptingRoleServiceSection.cs
- DataGridClipboardCellContent.cs
- DesignerSerializationManager.cs
- AppDomainUnloadedException.cs
- ListViewGroupConverter.cs
- DocumentAutomationPeer.cs
- List.cs
- InheritanceAttribute.cs
- EntityContainerRelationshipSet.cs
- FileRecordSequenceHelper.cs
- X509Utils.cs
- DbModificationClause.cs
- Adorner.cs
- ListDataBindEventArgs.cs
- EnumValidator.cs
- NavigatorInput.cs
- Adorner.cs
- WebPartEditorOkVerb.cs
- WebPartZoneBase.cs
- SoapAttributeOverrides.cs
- Rules.cs
- AttributeProviderAttribute.cs
- DataGridAddNewRow.cs
- XmlSchemaCollection.cs
- SafeCryptoKeyHandle.cs
- GridViewRowEventArgs.cs
- MemberMemberBinding.cs
- ToolboxItemCollection.cs
- FormViewInsertEventArgs.cs
- Configuration.cs
- TraceEventCache.cs
- PersonalizationProviderHelper.cs
- UniqueIdentifierService.cs
- TextBox.cs
- OledbConnectionStringbuilder.cs
- QueryCacheEntry.cs
- Calendar.cs
- ExecutionContext.cs
- QuaternionAnimation.cs
- SourceLocationProvider.cs
- BuildProvider.cs
- AvTrace.cs
- Int32KeyFrameCollection.cs
- TypeElement.cs
- QilInvokeEarlyBound.cs
- PassportIdentity.cs
- XmlRawWriter.cs
- DataErrorValidationRule.cs
- OleDbDataReader.cs
- ExpressionBuilder.cs
- SendKeys.cs