Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlObjectSerializerReadContextComplexJson.cs
- RequestNavigateEventArgs.cs
- ControlTemplate.cs
- XmlWrappingReader.cs
- AttributeQuery.cs
- TextControlDesigner.cs
- XmlQuerySequence.cs
- EdmToObjectNamespaceMap.cs
- Overlapped.cs
- EntityTransaction.cs
- NameValueFileSectionHandler.cs
- GridViewCellAutomationPeer.cs
- GreenMethods.cs
- RegexNode.cs
- WorkflowRuntimeEndpoint.cs
- SchemaNames.cs
- Cell.cs
- UpdateEventArgs.cs
- GeneralTransform3DGroup.cs
- BehaviorEditorPart.cs
- TagMapCollection.cs
- Polygon.cs
- EtwTrace.cs
- IntSecurity.cs
- TabControl.cs
- DataGridViewBand.cs
- PermissionToken.cs
- PriorityBindingExpression.cs
- ArrayList.cs
- BookmarkScopeHandle.cs
- ClosableStream.cs
- ImportCatalogPart.cs
- PageRanges.cs
- BitmapFrameEncode.cs
- safePerfProviderHandle.cs
- EpmHelper.cs
- BufferedGraphics.cs
- RelationshipEndCollection.cs
- ObjectConverter.cs
- Invariant.cs
- Int16AnimationUsingKeyFrames.cs
- ModifierKeysValueSerializer.cs
- OnOperation.cs
- RegionData.cs
- DoubleCollection.cs
- XmlWriterSettings.cs
- ListViewInsertEventArgs.cs
- LoginName.cs
- ArglessEventHandlerProxy.cs
- XmlSignificantWhitespace.cs
- AndCondition.cs
- EntityDataSourceView.cs
- XpsS0ValidatingLoader.cs
- WeakRefEnumerator.cs
- GridViewSortEventArgs.cs
- Annotation.cs
- ThemeDictionaryExtension.cs
- EntityViewGenerationAttribute.cs
- Brushes.cs
- IPipelineRuntime.cs
- RoutingChannelExtension.cs
- CrossContextChannel.cs
- TableLayoutSettings.cs
- BuildResultCache.cs
- HtmlControlAdapter.cs
- DataGridViewButtonColumn.cs
- EntitySetBase.cs
- EnumBuilder.cs
- EDesignUtil.cs
- ExpandSegmentCollection.cs
- RectAnimationUsingKeyFrames.cs
- FlagPanel.cs
- GiveFeedbackEvent.cs
- SpellerStatusTable.cs
- DomainLiteralReader.cs
- EditorZone.cs
- Grant.cs
- RuleConditionDialog.Designer.cs
- XpsS0ValidatingLoader.cs
- ConvertEvent.cs
- TabControlAutomationPeer.cs
- DataSourceXmlElementAttribute.cs
- DbProviderFactory.cs
- DelegatingTypeDescriptionProvider.cs
- EncryptedData.cs
- DataGridViewCellMouseEventArgs.cs
- WebPartsSection.cs
- DataKey.cs
- BitStream.cs
- Select.cs
- ToolStripContextMenu.cs
- ToolStripSeparatorRenderEventArgs.cs
- SemanticTag.cs
- TextSchema.cs
- IERequestCache.cs
- AnimationClockResource.cs
- SHA384Managed.cs
- PrimitiveCodeDomSerializer.cs
- Rect3DConverter.cs
- BaseParaClient.cs