Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- DecimalAnimationBase.cs
- FlagsAttribute.cs
- XmlExceptionHelper.cs
- ClientRuntime.cs
- IsolatedStorageFilePermission.cs
- remotingproxy.cs
- ProcessModelSection.cs
- WebRequestModulesSection.cs
- TransformerInfoCollection.cs
- DecimalAnimation.cs
- CodeRegionDirective.cs
- QilDataSource.cs
- SystemDiagnosticsSection.cs
- WebControlToolBoxItem.cs
- LineVisual.cs
- SecurityContext.cs
- MemberAssignmentAnalysis.cs
- XPathException.cs
- GroupByQueryOperator.cs
- BindToObject.cs
- XmlSerializer.cs
- XmlDataSourceNodeDescriptor.cs
- XpsInterleavingPolicy.cs
- CharUnicodeInfo.cs
- Boolean.cs
- OpacityConverter.cs
- TimeSpan.cs
- ObfuscationAttribute.cs
- CompositeActivityDesigner.cs
- PropertyEmitter.cs
- VerificationAttribute.cs
- ExpressionNormalizer.cs
- NonNullItemCollection.cs
- MdiWindowListItemConverter.cs
- FieldTemplateUserControl.cs
- ResumeStoryboard.cs
- BitmapCodecInfo.cs
- InteropAutomationProvider.cs
- HttpPostProtocolImporter.cs
- GridItemPattern.cs
- ExpressionEditorAttribute.cs
- XmlImplementation.cs
- TextTrailingWordEllipsis.cs
- RecognitionEventArgs.cs
- ToolStripSeparatorRenderEventArgs.cs
- BufferedGenericXmlSecurityToken.cs
- Splitter.cs
- DefaultMemberAttribute.cs
- BaseResourcesBuildProvider.cs
- BlockCollection.cs
- SeekStoryboard.cs
- TdsEnums.cs
- DropTarget.cs
- ParentQuery.cs
- GridViewUpdateEventArgs.cs
- SoapServerMethod.cs
- WindowsListViewSubItem.cs
- StylusPointProperties.cs
- GroupPartitionExpr.cs
- FilterRepeater.cs
- Literal.cs
- Stack.cs
- IntSecurity.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- XamlGridLengthSerializer.cs
- SystemIPGlobalStatistics.cs
- HMAC.cs
- PointKeyFrameCollection.cs
- ZipIOExtraFieldPaddingElement.cs
- NamespaceList.cs
- ValidatorUtils.cs
- MimeAnyImporter.cs
- FixedHyperLink.cs
- ToolStripStatusLabel.cs
- RadialGradientBrush.cs
- SamlDelegatingWriter.cs
- CasesDictionary.cs
- FormsAuthenticationEventArgs.cs
- BeginStoryboard.cs
- TimelineGroup.cs
- BindingBase.cs
- SynchronizingStream.cs
- XPathParser.cs
- ConvertTextFrag.cs
- XmlComment.cs
- SiteMapDataSourceView.cs
- ObjectDataSourceView.cs
- precedingquery.cs
- AgileSafeNativeMemoryHandle.cs
- ConnectionConsumerAttribute.cs
- AdRotator.cs
- LassoSelectionBehavior.cs
- ConfigDefinitionUpdates.cs
- SchemaCollectionCompiler.cs
- DependencyObject.cs
- LogLogRecordHeader.cs
- CrossSiteScriptingValidation.cs
- grammarelement.cs
- CommonGetThemePartSize.cs
- CheckBoxField.cs