Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- TriggerAction.cs
- Hash.cs
- SqlDataSourceCommandEventArgs.cs
- ComponentChangingEvent.cs
- Pair.cs
- compensatingcollection.cs
- CodeVariableDeclarationStatement.cs
- HtmlHead.cs
- TriggerActionCollection.cs
- PerformanceCounterPermission.cs
- HashMembershipCondition.cs
- SoapSchemaExporter.cs
- CategoryAttribute.cs
- MultilineStringConverter.cs
- FaultBookmark.cs
- DialogResultConverter.cs
- LocatorPartList.cs
- HttpRawResponse.cs
- XmlSignificantWhitespace.cs
- ConnectivityStatus.cs
- Parallel.cs
- DBSqlParserTableCollection.cs
- cookieexception.cs
- Button.cs
- FontStyleConverter.cs
- ReliableOutputConnection.cs
- ValueSerializer.cs
- DBCSCodePageEncoding.cs
- DataDocumentXPathNavigator.cs
- VirtualizingPanel.cs
- Matrix3D.cs
- CollectionChangedEventManager.cs
- MessageQueuePermissionAttribute.cs
- TextSegment.cs
- BackStopAuthenticationModule.cs
- SspiNegotiationTokenAuthenticatorState.cs
- DoubleLinkList.cs
- LayoutDump.cs
- ConnectionAcceptor.cs
- basecomparevalidator.cs
- Propagator.JoinPropagator.cs
- ListViewGroupConverter.cs
- DataChangedEventManager.cs
- HttpModulesSection.cs
- DebuggerAttributes.cs
- HyperlinkAutomationPeer.cs
- StrongNameUtility.cs
- MultipartIdentifier.cs
- AbsoluteQuery.cs
- RunClient.cs
- DataGridViewSelectedColumnCollection.cs
- WebPartCollection.cs
- Range.cs
- AssemblyFilter.cs
- CalendarBlackoutDatesCollection.cs
- PixelFormat.cs
- XmlSerializerAssemblyAttribute.cs
- TTSEngineProxy.cs
- TemplateField.cs
- DecoderNLS.cs
- StringConcat.cs
- diagnosticsswitches.cs
- SmiMetaDataProperty.cs
- SynchronizingStream.cs
- XmlSchemaGroupRef.cs
- ExecutorLocksHeldException.cs
- SafeViewOfFileHandle.cs
- TextLineBreak.cs
- WeakHashtable.cs
- Transform3DCollection.cs
- PageParser.cs
- DocumentApplicationJournalEntry.cs
- SelectionRange.cs
- TemplateAction.cs
- ServiceInfoCollection.cs
- RewritingPass.cs
- SpanIndex.cs
- VisualStyleInformation.cs
- ObjectResult.cs
- CompositeTypefaceMetrics.cs
- TableItemPattern.cs
- XmlSchemaAttribute.cs
- ToolStripItemImageRenderEventArgs.cs
- PropertyConverter.cs
- GraphicsContext.cs
- WorkflowNamespace.cs
- DataControlLinkButton.cs
- Empty.cs
- DataGridViewBindingCompleteEventArgs.cs
- GradientStop.cs
- Task.cs
- WebPartConnectionsCancelEventArgs.cs
- TabPage.cs
- SmtpMail.cs
- EmptyStringExpandableObjectConverter.cs
- SpellerInterop.cs
- DateTimeConstantAttribute.cs
- CurrentTimeZone.cs
- Camera.cs
- TheQuery.cs