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
- ThrowHelper.cs
- DataErrorValidationRule.cs
- DisplayInformation.cs
- Vertex.cs
- DragEvent.cs
- ReliableOutputSessionChannel.cs
- PreviewPageInfo.cs
- BitmapEffectDrawingContent.cs
- FileSystemEventArgs.cs
- ParsedAttributeCollection.cs
- InternalMappingException.cs
- CounterSample.cs
- XXXInfos.cs
- TextSelectionHelper.cs
- _UncName.cs
- RangeBase.cs
- RadioButtonRenderer.cs
- Vector3DAnimation.cs
- Rights.cs
- OdbcInfoMessageEvent.cs
- cache.cs
- TableCellAutomationPeer.cs
- QueryConverter.cs
- MenuItemCollection.cs
- OperationAbortedException.cs
- ProxyWebPart.cs
- EFAssociationProvider.cs
- WebBrowserSiteBase.cs
- SqlXml.cs
- MSAAEventDispatcher.cs
- DBCSCodePageEncoding.cs
- OracleBinary.cs
- PipelineComponent.cs
- TakeOrSkipQueryOperator.cs
- StrongNameIdentityPermission.cs
- StringSource.cs
- UrlAuthFailedErrorFormatter.cs
- ContainerVisual.cs
- HostAdapter.cs
- WebException.cs
- CompositeCollection.cs
- TextElementCollection.cs
- FilteredSchemaElementLookUpTable.cs
- GridViewDeleteEventArgs.cs
- LightweightCodeGenerator.cs
- RepeaterItemEventArgs.cs
- CryptoStream.cs
- DomNameTable.cs
- Resources.Designer.cs
- TextEditorThreadLocalStore.cs
- Span.cs
- Vector3DConverter.cs
- XmlSchemaSimpleContentRestriction.cs
- PropertyDescriptorComparer.cs
- SudsCommon.cs
- ZipIOExtraFieldPaddingElement.cs
- InputLanguageCollection.cs
- BaseServiceProvider.cs
- RoleBoolean.cs
- EmptyEnumerable.cs
- NamespaceExpr.cs
- QueryOptionExpression.cs
- EmptyStringExpandableObjectConverter.cs
- DataControlCommands.cs
- ByteStack.cs
- Thickness.cs
- ActivityExecutionContext.cs
- XmlWriterSettings.cs
- FixedPageProcessor.cs
- DesignTimeParseData.cs
- Clause.cs
- CFGGrammar.cs
- SqlMethods.cs
- PrimitiveCodeDomSerializer.cs
- SignalGate.cs
- SecurityResources.cs
- EndpointDiscoveryMetadata11.cs
- QuaternionValueSerializer.cs
- BaseInfoTable.cs
- ConfigurationManagerHelper.cs
- DataGridTablesFactory.cs
- CustomTypeDescriptor.cs
- AcceleratedTokenProviderState.cs
- ClaimTypes.cs
- XmlSchemaImporter.cs
- Mapping.cs
- QilParameter.cs
- selecteditemcollection.cs
- XamlStream.cs
- WmlPhoneCallAdapter.cs
- ProfileManager.cs
- Pkcs7Recipient.cs
- Deflater.cs
- TdsParserHelperClasses.cs
- SevenBitStream.cs
- SecurityElement.cs
- documentsequencetextcontainer.cs
- RtType.cs
- TextViewBase.cs
- TextProviderWrapper.cs