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
- ResourceContainerWrapper.cs
- XPathSingletonIterator.cs
- XPathChildIterator.cs
- PeerToPeerException.cs
- RelationshipWrapper.cs
- SimpleType.cs
- Logging.cs
- CompilerLocalReference.cs
- DocumentViewer.cs
- EntityViewGenerationAttribute.cs
- ITextView.cs
- EnumUnknown.cs
- TableLayoutPanelCellPosition.cs
- ExpressionHelper.cs
- CodeDomSerializerBase.cs
- XPathDocumentIterator.cs
- ping.cs
- RewritingPass.cs
- HttpModuleCollection.cs
- FormatException.cs
- TdsParserHelperClasses.cs
- DataRow.cs
- XmlTextEncoder.cs
- ObfuscateAssemblyAttribute.cs
- CngProperty.cs
- XmlResolver.cs
- LockCookie.cs
- IxmlLineInfo.cs
- AlphaSortedEnumConverter.cs
- ToolStripOverflow.cs
- CompiledRegexRunner.cs
- ExeContext.cs
- RichListBox.cs
- FixedSOMLineRanges.cs
- RemotingException.cs
- HttpNamespaceReservationInstallComponent.cs
- SecurityTokenAuthenticator.cs
- AstNode.cs
- SystemWebSectionGroup.cs
- MemoryFailPoint.cs
- ValueProviderWrapper.cs
- AssemblyEvidenceFactory.cs
- SqlDependencyListener.cs
- EnumerableRowCollection.cs
- WebPartTransformerCollection.cs
- SqlDataSourceFilteringEventArgs.cs
- StringUtil.cs
- IntSecurity.cs
- BinaryFormatter.cs
- DataGridViewElement.cs
- TableCellCollection.cs
- ResourceProviderFactory.cs
- HtmlMobileTextWriter.cs
- UrlMapping.cs
- TlsnegoTokenProvider.cs
- FileUpload.cs
- ListSourceHelper.cs
- PageHandlerFactory.cs
- EventLogger.cs
- SpeechUI.cs
- WSDualHttpBinding.cs
- QilTernary.cs
- EncryptedKeyIdentifierClause.cs
- userdatakeys.cs
- FileController.cs
- processwaithandle.cs
- GridViewRow.cs
- ComplexBindingPropertiesAttribute.cs
- TreeNodeClickEventArgs.cs
- GridViewSortEventArgs.cs
- ProgressBarRenderer.cs
- SQLBinary.cs
- ScriptManager.cs
- SuppressMergeCheckAttribute.cs
- Rect3D.cs
- Codec.cs
- Popup.cs
- MarkupCompilePass1.cs
- ExecutionEngineException.cs
- _NativeSSPI.cs
- WebHeaderCollection.cs
- OpenFileDialog.cs
- InfoCardService.cs
- SubclassTypeValidatorAttribute.cs
- MethodImplAttribute.cs
- HttpFileCollection.cs
- DataGridViewLinkCell.cs
- MulticastDelegate.cs
- RightNameExpirationInfoPair.cs
- SqlDataRecord.cs
- GradientSpreadMethodValidation.cs
- StreamUpdate.cs
- HotSpotCollection.cs
- TabControlAutomationPeer.cs
- BitmapDownload.cs
- PresentationTraceSources.cs
- SystemInfo.cs
- SplitterPanel.cs
- XmlConverter.cs
- WebPartEditorApplyVerb.cs