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
- XmlSerializationReader.cs
- Registry.cs
- VirtualizedContainerService.cs
- ImageMapEventArgs.cs
- FileDialogCustomPlace.cs
- GeometryCollection.cs
- SystemInfo.cs
- Wildcard.cs
- XmlResolver.cs
- FileVersionInfo.cs
- BamlRecordHelper.cs
- figurelength.cs
- WebPartChrome.cs
- ColumnCollectionEditor.cs
- OleDbConnection.cs
- XamlInt32CollectionSerializer.cs
- SerialStream.cs
- TraceShell.cs
- GraphicsContainer.cs
- DbFunctionCommandTree.cs
- unsafenativemethodsother.cs
- TypeSchema.cs
- SplineKeyFrames.cs
- ZipIOBlockManager.cs
- XmlSchemas.cs
- Int32Rect.cs
- KeyboardNavigation.cs
- TypeUtils.cs
- XmlSchemaException.cs
- MarkupWriter.cs
- PhysicalAddress.cs
- latinshape.cs
- UIElementParaClient.cs
- UpdateCommand.cs
- SiteMapHierarchicalDataSourceView.cs
- LineUtil.cs
- TripleDESCryptoServiceProvider.cs
- OracleTransaction.cs
- SignatureDescription.cs
- MessageFormatterConverter.cs
- SecuritySessionSecurityTokenProvider.cs
- ReadOnlyNameValueCollection.cs
- SqlTransaction.cs
- addressfiltermode.cs
- RelationshipEntry.cs
- LayoutEvent.cs
- InteropBitmapSource.cs
- MessageQueuePermissionEntryCollection.cs
- ExtractedStateEntry.cs
- CodeAccessSecurityEngine.cs
- HtmlForm.cs
- RoleManagerModule.cs
- CodeTryCatchFinallyStatement.cs
- WebSysDescriptionAttribute.cs
- HtmlElementCollection.cs
- RawStylusSystemGestureInputReport.cs
- XamlStackWriter.cs
- coordinator.cs
- WorkItem.cs
- SchemaMapping.cs
- QilLoop.cs
- ObjectItemCollection.cs
- IImplicitResourceProvider.cs
- XPathNodeInfoAtom.cs
- Journal.cs
- CommandManager.cs
- TableStyle.cs
- InputScopeNameConverter.cs
- TextViewSelectionProcessor.cs
- ActivationArguments.cs
- Image.cs
- XmlSchemaObjectTable.cs
- RegexCaptureCollection.cs
- DataColumnCollection.cs
- DateTimeConstantAttribute.cs
- MergeExecutor.cs
- ResourceContainer.cs
- UxThemeWrapper.cs
- EncoderFallback.cs
- NestedContainer.cs
- UpdateEventArgs.cs
- TypeConverterHelper.cs
- InfoCardBinaryReader.cs
- PackageFilter.cs
- FormatSettings.cs
- TriggerCollection.cs
- TreeChangeInfo.cs
- DocumentViewerBaseAutomationPeer.cs
- brushes.cs
- ListViewUpdateEventArgs.cs
- DelayedRegex.cs
- RepeatButtonAutomationPeer.cs
- BoundField.cs
- Menu.cs
- NameTable.cs
- ProfilePropertySettingsCollection.cs
- DefaultMemberAttribute.cs
- TextOnlyOutput.cs
- SQLDoubleStorage.cs
- WebPartRestoreVerb.cs