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
- ParseChildrenAsPropertiesAttribute.cs
- InstanceDescriptor.cs
- SimpleBitVector32.cs
- XmlAttributes.cs
- ToolStripSeparator.cs
- InheritanceRules.cs
- SelectionListComponentEditor.cs
- CodeTypeMember.cs
- MenuAdapter.cs
- DataServiceHost.cs
- ToolStripPanel.cs
- XmlBaseWriter.cs
- GPPOINTF.cs
- RootProfilePropertySettingsCollection.cs
- XmlSequenceWriter.cs
- SplitterPanel.cs
- DelegateBodyWriter.cs
- RoleGroupCollectionEditor.cs
- SiteMapDataSourceView.cs
- SafeThreadHandle.cs
- ArraySegment.cs
- RowType.cs
- MD5CryptoServiceProvider.cs
- _CacheStreams.cs
- PixelFormats.cs
- ModelVisual3D.cs
- ReadWriteObjectLock.cs
- hwndwrapper.cs
- StringValidator.cs
- SoapExtensionTypeElementCollection.cs
- RSAOAEPKeyExchangeFormatter.cs
- DetailsViewDeletedEventArgs.cs
- EditCommandColumn.cs
- CodeExpressionCollection.cs
- CreateUserWizardStep.cs
- DataGridViewCellParsingEventArgs.cs
- QilInvokeEarlyBound.cs
- InputMethod.cs
- IssuanceLicense.cs
- BindingMAnagerBase.cs
- DnsPermission.cs
- ConfigViewGenerator.cs
- ItemCheckEvent.cs
- BindingListCollectionView.cs
- DependencyPropertyChangedEventArgs.cs
- XmlSchemaElement.cs
- QilTernary.cs
- InspectionWorker.cs
- ResourceWriter.cs
- BitVector32.cs
- Guid.cs
- GroupStyle.cs
- IdentityNotMappedException.cs
- AdRotator.cs
- _AutoWebProxyScriptEngine.cs
- CroppedBitmap.cs
- BitmapScalingModeValidation.cs
- ZoomingMessageFilter.cs
- RightsController.cs
- HostProtectionPermission.cs
- SqlExpander.cs
- Knowncolors.cs
- DynamicDiscoSearcher.cs
- HandleValueEditor.cs
- ContainerControl.cs
- BitmapEffectInputData.cs
- LogStore.cs
- NonParentingControl.cs
- EnterpriseServicesHelper.cs
- CustomAttribute.cs
- SystemTcpStatistics.cs
- BuildProvidersCompiler.cs
- PostBackTrigger.cs
- RSAPKCS1KeyExchangeFormatter.cs
- BitmapDownload.cs
- MenuCommandService.cs
- ValidationService.cs
- WebChannelFactory.cs
- ZipIORawDataFileBlock.cs
- InstanceNormalEvent.cs
- RoutedUICommand.cs
- WebPartConnectionsConnectVerb.cs
- RelatedEnd.cs
- DisplayClaim.cs
- SerializationAttributes.cs
- IdentityHolder.cs
- CompilationLock.cs
- DisplayMemberTemplateSelector.cs
- TextAction.cs
- Debugger.cs
- SafeCryptoHandles.cs
- BezierSegment.cs
- ObjectPersistData.cs
- SizeConverter.cs
- DataGridViewColumnDesigner.cs
- WindowsStatic.cs
- ToolStripLocationCancelEventArgs.cs
- FlagsAttribute.cs
- InstalledFontCollection.cs
- BlurBitmapEffect.cs