Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Shared / MS / Internal / FloatUtil.cs / 1 / 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 : adsmith - Created this header // 05/20/2003 : adsmith - 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 : adsmith - Created this header // 05/20/2003 : adsmith - 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
- Binding.cs
- UnsafePeerToPeerMethods.cs
- DataGridRow.cs
- FileRecordSequenceCompletedAsyncResult.cs
- DataGridTableCollection.cs
- ExpressionBuilderCollection.cs
- Win32.cs
- PropertyHelper.cs
- PolicyValidationException.cs
- FileClassifier.cs
- EntitySetBase.cs
- SecurityListenerSettingsLifetimeManager.cs
- ComplexObject.cs
- AddInControllerImpl.cs
- SecurityRuntime.cs
- Publisher.cs
- XmlWrappingReader.cs
- CustomWebEventKey.cs
- ProgressBarBrushConverter.cs
- CultureMapper.cs
- SqlDataSourceSelectingEventArgs.cs
- WindowsFormsHostPropertyMap.cs
- BeginStoryboard.cs
- FlowDocumentScrollViewer.cs
- DataGridLinkButton.cs
- DataGridViewToolTip.cs
- HttpListenerContext.cs
- EntityDataSourceColumn.cs
- TemplateControlCodeDomTreeGenerator.cs
- DictionaryContent.cs
- ClientRolePrincipal.cs
- ButtonStandardAdapter.cs
- X509ChainElement.cs
- Parser.cs
- Stroke2.cs
- ProvidePropertyAttribute.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- Decoder.cs
- ForeignKeyFactory.cs
- ContractNamespaceAttribute.cs
- WindowsHyperlink.cs
- GeneralTransform3D.cs
- Enumerable.cs
- InfoCardAsymmetricCrypto.cs
- IgnoreFlushAndCloseStream.cs
- ApplicationException.cs
- TextSpan.cs
- RenderData.cs
- ResourceDescriptionAttribute.cs
- Substitution.cs
- ModuleBuilderData.cs
- OperatingSystem.cs
- OrderedEnumerableRowCollection.cs
- OleDragDropHandler.cs
- XmlCharType.cs
- DirectoryNotFoundException.cs
- SqlTriggerContext.cs
- MenuCommands.cs
- LocalsItemDescription.cs
- DateBoldEvent.cs
- IsolatedStorageFileStream.cs
- QuotedPrintableStream.cs
- FtpCachePolicyElement.cs
- SoapDocumentMethodAttribute.cs
- QueryableDataSourceEditData.cs
- PictureBox.cs
- SerializationSectionGroup.cs
- BitmapEffectDrawingContent.cs
- ComboBoxRenderer.cs
- TemplatePropertyEntry.cs
- AxHost.cs
- DateTimeFormatInfoScanner.cs
- SkinBuilder.cs
- SyndicationSerializer.cs
- ToolStripItemGlyph.cs
- WebPartDescriptionCollection.cs
- WsdlHelpGeneratorElement.cs
- FixedSOMSemanticBox.cs
- BinarySecretKeyIdentifierClause.cs
- FunctionParameter.cs
- GridEntryCollection.cs
- _LocalDataStoreMgr.cs
- MediaSystem.cs
- EnvironmentPermission.cs
- InheritanceAttribute.cs
- SmiContextFactory.cs
- SharedPersonalizationStateInfo.cs
- KnowledgeBase.cs
- DataGridLinkButton.cs
- BaseDataListPage.cs
- CaseInsensitiveHashCodeProvider.cs
- FillBehavior.cs
- AccessorTable.cs
- BulletedList.cs
- Duration.cs
- GroupQuery.cs
- RemotingAttributes.cs
- ListViewEditEventArgs.cs
- HttpHandlersSection.cs
- Select.cs