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
- FilePrompt.cs
- StrongName.cs
- ResXFileRef.cs
- MetadataUtilsSmi.cs
- TdsParameterSetter.cs
- SignedPkcs7.cs
- COMException.cs
- TypeUsageBuilder.cs
- DesignerProperties.cs
- PropertyBuilder.cs
- SqlErrorCollection.cs
- LockedBorderGlyph.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- URLMembershipCondition.cs
- XmlException.cs
- WriteLine.cs
- LocatorManager.cs
- _ScatterGatherBuffers.cs
- TextDecorationLocationValidation.cs
- DynamicQueryableWrapper.cs
- COM2ExtendedBrowsingHandler.cs
- SystemGatewayIPAddressInformation.cs
- DesignTimeValidationFeature.cs
- BitmapMetadataBlob.cs
- X509ChainElement.cs
- UIPermission.cs
- EntitySqlQueryBuilder.cs
- ClientConfigPaths.cs
- DirectoryRedirect.cs
- TcpHostedTransportConfiguration.cs
- ContextMarshalException.cs
- XmlSchemaDatatype.cs
- SqlColumnizer.cs
- ImageConverter.cs
- XmlSchemaSubstitutionGroup.cs
- FormsAuthenticationEventArgs.cs
- TransactionException.cs
- cryptoapiTransform.cs
- XmlTextReader.cs
- ComplexTypeEmitter.cs
- ActivityWithResultValueSerializer.cs
- EdmFunction.cs
- FieldMetadata.cs
- ThreadStateException.cs
- typedescriptorpermission.cs
- DeferredTextReference.cs
- WMIInterop.cs
- ToolboxItemAttribute.cs
- WebServiceClientProxyGenerator.cs
- CodeAccessPermission.cs
- TreeNode.cs
- ProgressBarRenderer.cs
- ColorContextHelper.cs
- ExceptionWrapper.cs
- wgx_sdk_version.cs
- IntranetCredentialPolicy.cs
- SatelliteContractVersionAttribute.cs
- ImageInfo.cs
- PagerSettings.cs
- SmtpCommands.cs
- StandardCommandToolStripMenuItem.cs
- EventMappingSettings.cs
- QueueProcessor.cs
- VSWCFServiceContractGenerator.cs
- X509SecurityTokenAuthenticator.cs
- PagePropertiesChangingEventArgs.cs
- Choices.cs
- ToolTipService.cs
- TableCell.cs
- MouseGestureConverter.cs
- GradientStopCollection.cs
- Timer.cs
- _LocalDataStoreMgr.cs
- AuthorizationRule.cs
- RotationValidation.cs
- MarkerProperties.cs
- WebPartManagerInternals.cs
- DynamicValueConverter.cs
- ContextMenuService.cs
- SoapMessage.cs
- ArgumentOutOfRangeException.cs
- MultipleFilterMatchesException.cs
- XslTransform.cs
- ChangeTracker.cs
- RegexParser.cs
- CompModSwitches.cs
- TabRenderer.cs
- DataGridViewColumnCollection.cs
- WebServiceTypeData.cs
- MarkupExtensionReturnTypeAttribute.cs
- IResourceProvider.cs
- HitTestFilterBehavior.cs
- SafeSystemMetrics.cs
- MsmqBindingMonitor.cs
- InputLangChangeEvent.cs
- TypeElement.cs
- Int32CollectionConverter.cs
- ParenthesizePropertyNameAttribute.cs
- KeyedHashAlgorithm.cs
- PreProcessInputEventArgs.cs