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
- DataTablePropertyDescriptor.cs
- SQlBooleanStorage.cs
- FusionWrap.cs
- CreateUserErrorEventArgs.cs
- DataTemplateSelector.cs
- ResourcesBuildProvider.cs
- Rotation3DAnimation.cs
- PingOptions.cs
- CodeDomConfigurationHandler.cs
- documentsequencetextview.cs
- EntityDataSourceSelectingEventArgs.cs
- EventHandlers.cs
- SystemBrushes.cs
- SqlError.cs
- PreservationFileReader.cs
- WebMessageBodyStyleHelper.cs
- DbDataReader.cs
- Soap12FormatExtensions.cs
- ListenerConnectionModeReader.cs
- SmtpMail.cs
- DetailsViewPagerRow.cs
- Oid.cs
- RuleSettings.cs
- MobileControlPersister.cs
- SeekableReadStream.cs
- HttpCacheParams.cs
- QueryRewriter.cs
- PropertyGroupDescription.cs
- WsdlInspector.cs
- MessageParameterAttribute.cs
- ModifiableIteratorCollection.cs
- TreeViewEvent.cs
- ModelItemCollection.cs
- XmlQualifiedNameTest.cs
- DoubleCollectionConverter.cs
- DataContractSerializerSection.cs
- ToolStripArrowRenderEventArgs.cs
- ExpressionSelection.cs
- AccessedThroughPropertyAttribute.cs
- ThicknessAnimation.cs
- CultureNotFoundException.cs
- InstallerTypeAttribute.cs
- ErrorHandler.cs
- ToolStripPanelSelectionGlyph.cs
- SocketException.cs
- DocumentManager.cs
- MemberPathMap.cs
- ButtonColumn.cs
- XPathNodePointer.cs
- DataGridViewTopRowAccessibleObject.cs
- CachedTypeface.cs
- AutoResizedEvent.cs
- OutputCacheProfileCollection.cs
- XmlIgnoreAttribute.cs
- FixedTextPointer.cs
- SessionStateModule.cs
- RadioButtonBaseAdapter.cs
- ObjectViewEntityCollectionData.cs
- CancellationTokenSource.cs
- Span.cs
- Point3DIndependentAnimationStorage.cs
- XmlMemberMapping.cs
- FontSource.cs
- SetStateDesigner.cs
- Emitter.cs
- DataControlCommands.cs
- BodyWriter.cs
- IdentifierService.cs
- Pen.cs
- ProjectionNode.cs
- ObjectIDGenerator.cs
- FixedTextView.cs
- IUnknownConstantAttribute.cs
- TemplateBuilder.cs
- LockCookie.cs
- NullableFloatAverageAggregationOperator.cs
- ReceiveActivityDesignerTheme.cs
- WindowHideOrCloseTracker.cs
- PageSettings.cs
- WebDescriptionAttribute.cs
- WebConfigurationManager.cs
- TextRunTypographyProperties.cs
- FtpWebRequest.cs
- ItemCollection.cs
- KnownTypes.cs
- XmlDataProvider.cs
- Bold.cs
- OdbcParameter.cs
- CompatibleComparer.cs
- FigureParagraph.cs
- GenericAuthenticationEventArgs.cs
- UdpMessageProperty.cs
- DrawItemEvent.cs
- ParentQuery.cs
- SuppressMessageAttribute.cs
- BitmapScalingModeValidation.cs
- Logging.cs
- SimpleExpression.cs
- BCLDebug.cs
- ObjectItemCollection.cs