Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / 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 : [....] - 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
- TextElementAutomationPeer.cs
- TCPListener.cs
- PromptStyle.cs
- InputReferenceExpression.cs
- PageFunction.cs
- X509Extension.cs
- CancellationTokenSource.cs
- CreateUserWizardDesigner.cs
- DataControlReference.cs
- BamlCollectionHolder.cs
- TableCellAutomationPeer.cs
- DataContractFormatAttribute.cs
- CaseInsensitiveOrdinalStringComparer.cs
- KerberosSecurityTokenAuthenticator.cs
- GeneralTransformGroup.cs
- OleDbError.cs
- XmlSchemaExporter.cs
- Message.cs
- SchemaImporterExtensionElement.cs
- IsolatedStoragePermission.cs
- FontInfo.cs
- BaseTemplateCodeDomTreeGenerator.cs
- StylusButtonCollection.cs
- RoutedEvent.cs
- PathSegment.cs
- ToolStripItemEventArgs.cs
- TransportContext.cs
- MouseOverProperty.cs
- ContextMenuService.cs
- TreeView.cs
- SmiRequestExecutor.cs
- InstanceHandleConflictException.cs
- GenericFlowSwitchHelper.cs
- Crc32.cs
- BroadcastEventHelper.cs
- DataGridViewCellStyle.cs
- ImageDrawing.cs
- MetadataArtifactLoaderResource.cs
- EventLogEntryCollection.cs
- GregorianCalendarHelper.cs
- ModelTreeManager.cs
- ContainerUtilities.cs
- CombinedGeometry.cs
- ChangeConflicts.cs
- PropertyGridCommands.cs
- ServerValidateEventArgs.cs
- CodeDomSerializerBase.cs
- SqlStatistics.cs
- XsdBuilder.cs
- CopyNodeSetAction.cs
- DiscardableAttribute.cs
- FixedSOMPageConstructor.cs
- Tablet.cs
- StyleModeStack.cs
- isolationinterop.cs
- ElementProxy.cs
- _OSSOCK.cs
- XamlHostingSection.cs
- CollectionChangedEventManager.cs
- ConfigurationValue.cs
- OleDbConnectionInternal.cs
- PrinterResolution.cs
- InvokeWebServiceDesigner.cs
- TextTrailingWordEllipsis.cs
- RuleSetDialog.cs
- MetadataPropertyvalue.cs
- TextUtf8RawTextWriter.cs
- SpeakInfo.cs
- SQLDateTimeStorage.cs
- CultureSpecificStringDictionary.cs
- IndexedGlyphRun.cs
- DateTimeConverter2.cs
- CharStorage.cs
- MobileUserControlDesigner.cs
- StoragePropertyMapping.cs
- XmlEntityReference.cs
- EncoderExceptionFallback.cs
- AttributeEmitter.cs
- SerializationFieldInfo.cs
- AffineTransform3D.cs
- LogicalTreeHelper.cs
- InputLanguageCollection.cs
- CacheOutputQuery.cs
- ContextToken.cs
- Camera.cs
- filewebrequest.cs
- CheckBoxField.cs
- RepeaterItem.cs
- XmlAttributeCache.cs
- ToolboxComponentsCreatingEventArgs.cs
- VarRefManager.cs
- RequestCachingSection.cs
- ApplicationManager.cs
- GlyphRunDrawing.cs
- XmlSerializationGeneratedCode.cs
- HtmlForm.cs
- Model3D.cs
- NonSerializedAttribute.cs
- Directory.cs
- ConstantProjectedSlot.cs