Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CaseInsensitiveHashCodeProvider.cs
- DataPagerFieldCommandEventArgs.cs
- DynamicFilter.cs
- MarshalByValueComponent.cs
- SafeNativeMethodsCLR.cs
- AnnotationResourceCollection.cs
- SafeMemoryMappedFileHandle.cs
- XsdCachingReader.cs
- AutoResizedEvent.cs
- CollectionViewGroupInternal.cs
- EnumerableRowCollection.cs
- PngBitmapEncoder.cs
- WebBrowsableAttribute.cs
- util.cs
- AuthenticationService.cs
- CssStyleCollection.cs
- BuildProvider.cs
- DoubleUtil.cs
- XmlAggregates.cs
- XmlWrappingReader.cs
- SystemUnicastIPAddressInformation.cs
- SuppressMergeCheckAttribute.cs
- PersonalizationStateQuery.cs
- Base64Encoder.cs
- SystemInfo.cs
- SqlNotificationEventArgs.cs
- CategoriesDocument.cs
- NativeWindow.cs
- ObjectQueryExecutionPlan.cs
- ListViewInsertionMark.cs
- CompilerResults.cs
- PartialClassGenerationTask.cs
- UriSectionReader.cs
- ByteStorage.cs
- SqlFunctionAttribute.cs
- MaskInputRejectedEventArgs.cs
- StringPropertyBuilder.cs
- CollectionBase.cs
- PeerNodeTraceRecord.cs
- AnnouncementInnerClient11.cs
- SecurityPolicySection.cs
- SqlDesignerDataSourceView.cs
- CollectionViewGroupRoot.cs
- Resources.Designer.cs
- ExportOptions.cs
- BrowserTree.cs
- XhtmlStyleClass.cs
- DrawingCollection.cs
- TextElementAutomationPeer.cs
- LexicalChunk.cs
- TextModifier.cs
- XmlBufferReader.cs
- DataSetSchema.cs
- WebColorConverter.cs
- CopyOnWriteList.cs
- PrivilegeNotHeldException.cs
- RightsManagementPermission.cs
- UnsafeNativeMethods.cs
- DataGridViewCellParsingEventArgs.cs
- ImpersonateTokenRef.cs
- MatrixCamera.cs
- ProfileBuildProvider.cs
- TextServicesCompartmentEventSink.cs
- SystemThemeKey.cs
- Descriptor.cs
- mactripleDES.cs
- MetaData.cs
- CurrentChangingEventArgs.cs
- XmlIlGenerator.cs
- ListSortDescriptionCollection.cs
- RegexParser.cs
- LogStore.cs
- GradientStop.cs
- CodeCompileUnit.cs
- JpegBitmapEncoder.cs
- SafeNativeMethodsMilCoreApi.cs
- ProxyRpc.cs
- LocalizableResourceBuilder.cs
- SqlDataReaderSmi.cs
- SecurityBindingElementImporter.cs
- BindingsCollection.cs
- ZipIOBlockManager.cs
- IdentityManager.cs
- RootAction.cs
- TabControl.cs
- GeometryGroup.cs
- PropertyChangedEventArgs.cs
- _CommandStream.cs
- ComplexTypeEmitter.cs
- SmtpAuthenticationManager.cs
- RoutedEventHandlerInfo.cs
- BuildProvider.cs
- OdbcRowUpdatingEvent.cs
- QueryCacheKey.cs
- XmlILTrace.cs
- WebSysDisplayNameAttribute.cs
- HttpWriter.cs
- DecimalAnimationUsingKeyFrames.cs
- UriTemplateMatch.cs
- XPathAncestorQuery.cs