Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- Comparer.cs
- documentation.cs
- WindowsContainer.cs
- CursorConverter.cs
- SchemaLookupTable.cs
- NavigationFailedEventArgs.cs
- EventPropertyMap.cs
- FreezableCollection.cs
- XmlSubtreeReader.cs
- ReadOnlyDataSourceView.cs
- xdrvalidator.cs
- TypedTableBaseExtensions.cs
- ProcessThread.cs
- PolicyLevel.cs
- AdvancedBindingPropertyDescriptor.cs
- UInt32.cs
- ContextInformation.cs
- ReferenceEqualityComparer.cs
- InputReport.cs
- LinqDataSourceDeleteEventArgs.cs
- HttpConfigurationSystem.cs
- InlineUIContainer.cs
- TypeListConverter.cs
- SystemColors.cs
- DomainConstraint.cs
- CodeSnippetStatement.cs
- InvokeGenerator.cs
- NavigationFailedEventArgs.cs
- WebRequestModuleElementCollection.cs
- BuildManagerHost.cs
- CharacterHit.cs
- ExtensionSimplifierMarkupObject.cs
- ParseHttpDate.cs
- GlyphRunDrawing.cs
- Double.cs
- DbParameterCollectionHelper.cs
- BeginEvent.cs
- HttpModuleActionCollection.cs
- FileLogRecord.cs
- DataFormats.cs
- StringHelper.cs
- SEHException.cs
- DelegatingConfigHost.cs
- CodeGenerator.cs
- ItemContainerPattern.cs
- MaterialCollection.cs
- PointHitTestParameters.cs
- HttpRawResponse.cs
- PageCodeDomTreeGenerator.cs
- XamlParser.cs
- DefaultMemberAttribute.cs
- CompiledXpathExpr.cs
- TabControl.cs
- MenuItemStyleCollection.cs
- AnnouncementDispatcherAsyncResult.cs
- IsolatedStoragePermission.cs
- ClientEventManager.cs
- KeyTimeConverter.cs
- CqlQuery.cs
- QueryContinueDragEvent.cs
- ToolStripDesignerUtils.cs
- EventsTab.cs
- MemberMaps.cs
- DataGridViewButtonColumn.cs
- PostBackTrigger.cs
- InternalConfigRoot.cs
- BaseAsyncResult.cs
- Pointer.cs
- ServiceOperation.cs
- SessionEndingEventArgs.cs
- BookmarkEventArgs.cs
- RegexMatchCollection.cs
- MessageQueuePermissionAttribute.cs
- Literal.cs
- LongValidator.cs
- DecoderReplacementFallback.cs
- ReflectionTypeLoadException.cs
- FixedSOMPageConstructor.cs
- ClaimTypeElement.cs
- Point3D.cs
- SettingsProviderCollection.cs
- HttpCacheVary.cs
- TypeSystem.cs
- TypeGeneratedEventArgs.cs
- CodeRegionDirective.cs
- HatchBrush.cs
- TextDecorationCollection.cs
- PriorityQueue.cs
- URLIdentityPermission.cs
- UriSection.cs
- TypeDescriptionProviderAttribute.cs
- XmlEncoding.cs
- ActivityCollectionMarkupSerializer.cs
- SaveFileDialogDesigner.cs
- IisTraceWebEventProvider.cs
- ZipIOExtraFieldElement.cs
- ComplexBindingPropertiesAttribute.cs
- LookupBindingPropertiesAttribute.cs
- UmAlQuraCalendar.cs
- PropertiesTab.cs