Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / 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 : [....] - 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
- BitmapEffectDrawingContextWalker.cs
- TypeLoadException.cs
- ControlParameter.cs
- DataControlFieldCollection.cs
- ModelPerspective.cs
- EntityDataSourceChangingEventArgs.cs
- ObjectListShowCommandsEventArgs.cs
- Number.cs
- WebRequestModuleElementCollection.cs
- QueryValue.cs
- TrustLevel.cs
- ScriptResourceAttribute.cs
- SqlProvider.cs
- ValidationResults.cs
- NativeMethods.cs
- DuplicateWaitObjectException.cs
- EventSinkHelperWriter.cs
- StorageBasedPackageProperties.cs
- FixedSOMTextRun.cs
- IsolatedStorageFileStream.cs
- PrePostDescendentsWalker.cs
- ResourcePermissionBaseEntry.cs
- DoubleConverter.cs
- LinqDataSourceValidationException.cs
- RegisteredDisposeScript.cs
- WaitHandleCannotBeOpenedException.cs
- Polyline.cs
- BitmapEffectDrawing.cs
- Panel.cs
- GeneralTransformCollection.cs
- XmlQueryContext.cs
- GenericWebPart.cs
- MultiPageTextView.cs
- WsdlWriter.cs
- DelegateSerializationHolder.cs
- MimeFormatExtensions.cs
- TextTreeText.cs
- DataPagerFieldCollection.cs
- GridViewEditEventArgs.cs
- EncodingConverter.cs
- NativeActivity.cs
- XamlTypeMapper.cs
- PresentationTraceSources.cs
- UpnEndpointIdentityExtension.cs
- DynamicEntity.cs
- FilterElement.cs
- XPathAncestorIterator.cs
- SocketElement.cs
- ExtenderProvidedPropertyAttribute.cs
- Base64Encoder.cs
- XmlObjectSerializerContext.cs
- UpDownEvent.cs
- SafeFileMapViewHandle.cs
- XmlSerializerFactory.cs
- UserControl.cs
- WebSysDescriptionAttribute.cs
- ValidationUtility.cs
- FileCodeGroup.cs
- EntityDataSourceContextCreatingEventArgs.cs
- CssTextWriter.cs
- OracleParameterBinding.cs
- CqlWriter.cs
- TextRange.cs
- Empty.cs
- EntityDesignerDataSourceView.cs
- DelegateArgument.cs
- XamlUtilities.cs
- CodeAccessSecurityEngine.cs
- TextParaLineResult.cs
- ApplicationActivator.cs
- FrameworkElementFactory.cs
- DefaultValidator.cs
- WebPartZone.cs
- Vector3DKeyFrameCollection.cs
- MetadataItemEmitter.cs
- WebBrowserDesigner.cs
- XamlStream.cs
- TimeStampChecker.cs
- SiteMapDataSource.cs
- XmlDocumentType.cs
- SearchExpression.cs
- storepermission.cs
- TypeDescriptionProviderAttribute.cs
- TreeNodeBindingCollection.cs
- httpapplicationstate.cs
- TokenFactoryFactory.cs
- TextServicesPropertyRanges.cs
- SchemaLookupTable.cs
- RootBrowserWindowProxy.cs
- ScriptReferenceEventArgs.cs
- WebHttpDispatchOperationSelector.cs
- NativeRightsManagementAPIsStructures.cs
- DigestTraceRecordHelper.cs
- CatchBlock.cs
- DataGridViewElement.cs
- ComponentConverter.cs
- Module.cs
- M3DUtil.cs
- SubstitutionResponseElement.cs
- uribuilder.cs