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
- RSAProtectedConfigurationProvider.cs
- DetailsViewUpdatedEventArgs.cs
- EventToken.cs
- ExceptionValidationRule.cs
- XmlCDATASection.cs
- SqlDataSource.cs
- documentsequencetextview.cs
- HandlerFactoryCache.cs
- DataGridTablesFactory.cs
- OdbcInfoMessageEvent.cs
- ToolBarButtonDesigner.cs
- DataObject.cs
- DependentTransaction.cs
- SqlMethodAttribute.cs
- NavigationPropertyEmitter.cs
- SQLGuidStorage.cs
- EditorPartChrome.cs
- ExtensionElement.cs
- LineGeometry.cs
- SqlCharStream.cs
- XmlSchemaParticle.cs
- SQLDouble.cs
- FontStyleConverter.cs
- AnonymousIdentificationSection.cs
- HttpVersion.cs
- FillErrorEventArgs.cs
- VersionedStream.cs
- DesignerActionListCollection.cs
- Stopwatch.cs
- NotificationContext.cs
- LayoutEditorPart.cs
- XmlNodeReader.cs
- JpegBitmapEncoder.cs
- ByteStreamMessageEncodingElement.cs
- CompiledRegexRunner.cs
- WebCategoryAttribute.cs
- HttpHostedTransportConfiguration.cs
- XmlWriter.cs
- InitializationEventAttribute.cs
- TextElement.cs
- PerformanceCounterManager.cs
- ScriptResourceHandler.cs
- ComplexLine.cs
- CheckedListBox.cs
- UserThread.cs
- RedirectionProxy.cs
- GridViewSortEventArgs.cs
- CapabilitiesState.cs
- AdjustableArrowCap.cs
- coordinatorscratchpad.cs
- ScrollItemProviderWrapper.cs
- MarkerProperties.cs
- BindToObject.cs
- DBSchemaTable.cs
- SEHException.cs
- LocalizableResourceBuilder.cs
- CleanUpVirtualizedItemEventArgs.cs
- MobileListItem.cs
- httpstaticobjectscollection.cs
- PerformanceCountersElement.cs
- FixedSOMPageElement.cs
- SHA256Cng.cs
- HttpRuntimeSection.cs
- SecurityException.cs
- _NTAuthentication.cs
- SerializationException.cs
- CodeNamespaceCollection.cs
- BitmapImage.cs
- PtsContext.cs
- XmlFormatWriterGenerator.cs
- TextLineBreak.cs
- RightsManagementInformation.cs
- TripleDES.cs
- ActivityCodeDomSerializationManager.cs
- Array.cs
- IPAddress.cs
- DispatcherExceptionEventArgs.cs
- VoiceInfo.cs
- ApplicationCommands.cs
- InputMethodStateChangeEventArgs.cs
- TdsParserSafeHandles.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- WindowsSolidBrush.cs
- _SslSessionsCache.cs
- StoreAnnotationsMap.cs
- ChannelServices.cs
- LambdaCompiler.cs
- OleDbSchemaGuid.cs
- StateItem.cs
- SafeRegistryKey.cs
- CompatibleComparer.cs
- __ConsoleStream.cs
- ToolboxItemCollection.cs
- ChtmlTextWriter.cs
- OptimalBreakSession.cs
- DependencySource.cs
- EditCommandColumn.cs
- ReadContentAsBinaryHelper.cs
- UriExt.cs
- Filter.cs