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
- DPAPIProtectedConfigurationProvider.cs
- XamlWrappingReader.cs
- HitTestParameters.cs
- NamedPermissionSet.cs
- UpdateManifestForBrowserApplication.cs
- WindowsClientCredential.cs
- DoubleUtil.cs
- State.cs
- TransformPatternIdentifiers.cs
- HtmlInputButton.cs
- documentsequencetextcontainer.cs
- SessionEndingCancelEventArgs.cs
- InkSerializer.cs
- AnnotationService.cs
- ResourceDescriptionAttribute.cs
- CacheChildrenQuery.cs
- xml.cs
- GridViewAutomationPeer.cs
- IntSumAggregationOperator.cs
- TraceSection.cs
- FreeFormDragDropManager.cs
- ContextActivityUtils.cs
- TranslateTransform3D.cs
- SpStreamWrapper.cs
- _LocalDataStore.cs
- ClusterSafeNativeMethods.cs
- MouseButtonEventArgs.cs
- ExceptionDetail.cs
- COAUTHINFO.cs
- ZipIOLocalFileBlock.cs
- StsCommunicationException.cs
- UnsafeMethods.cs
- PageCatalogPart.cs
- ItemMap.cs
- AsymmetricSignatureDeformatter.cs
- WebConfigurationHost.cs
- ToolStripDropDown.cs
- ContentControl.cs
- WebPartConnectionsConnectVerb.cs
- TextTreeInsertElementUndoUnit.cs
- Header.cs
- CodeTypeReferenceCollection.cs
- LinkConverter.cs
- ColorEditor.cs
- UnsafeCollabNativeMethods.cs
- PlainXmlWriter.cs
- DefaultAutoFieldGenerator.cs
- RichTextBoxDesigner.cs
- ColorTypeConverter.cs
- DataProtection.cs
- WebPartConnectionsEventArgs.cs
- SchemaInfo.cs
- MenuTracker.cs
- ModuleBuilderData.cs
- WebPartActionVerb.cs
- AsyncCodeActivity.cs
- HandlerFactoryCache.cs
- CaseInsensitiveOrdinalStringComparer.cs
- RequestCachePolicyConverter.cs
- MasterPageParser.cs
- PageThemeBuildProvider.cs
- DashStyles.cs
- StateMachineWorkflowInstance.cs
- PerformanceCounterLib.cs
- RefreshPropertiesAttribute.cs
- Int32CollectionConverter.cs
- TemplateKey.cs
- VirtualPath.cs
- InputManager.cs
- FreezableOperations.cs
- GetPolicyDetailsRequest.cs
- ObjectNotFoundException.cs
- TrackingMemoryStream.cs
- SiteMapHierarchicalDataSourceView.cs
- AttachedPropertyBrowsableAttribute.cs
- TypeGeneratedEventArgs.cs
- IntSecurity.cs
- CodeObject.cs
- CopyNodeSetAction.cs
- CutCopyPasteHelper.cs
- SparseMemoryStream.cs
- messageonlyhwndwrapper.cs
- DocumentPaginator.cs
- BrowserCapabilitiesCodeGenerator.cs
- DependencyPropertyChangedEventArgs.cs
- XmlChildNodes.cs
- XPathException.cs
- DataQuery.cs
- XmlSubtreeReader.cs
- Vector3DCollection.cs
- BooleanStorage.cs
- BinaryCommonClasses.cs
- RichTextBoxAutomationPeer.cs
- SubMenuStyleCollection.cs
- CancellationToken.cs
- PlainXmlSerializer.cs
- BaseCAMarshaler.cs
- WindowsSysHeader.cs
- ExpandoObject.cs
- IfAction.cs