C# Class UnityEngine.NUnit.Framework.Constraints.FloatingPointNumerics

Helper routines for working with floating point numbers

The floating point comparison code is based on this excellent article: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

"ULP" means Unit in the Last Place and in the context of this library refers to the distance between two adjacent floating point numbers. IEEE floating point numbers can only represent a finite subset of natural numbers, with greater accuracy for smaller numbers and lower accuracy for very large numbers.

If a comparison is allowed "2 ulps" of deviation, that means the values are allowed to deviate by up to 2 adjacent floating point values, which might be as low as 0.0000001 for small numbers or as high as 10.0 for large numbers.

Mostrar archivo Open project: Unity-Technologies/nunitv2

Public Methods

Method Description
AreAlmostEqualUlps ( double left, double right, long maxUlps ) : bool

Compares two double precision floating point values for equality

Double precision floating point values can only represent a limited series of natural numbers. For example, the values 2.0000000000000000 and 2.0000000000000004 can be stored in a double, but nothing inbetween them.

This comparison will count how many possible double precision floating point values are between the left and the right number. If the number of possible values between both numbers is less than or equal to maxUlps, then the numbers are considered as being equal.

Implementation partially follows the code outlined here: http://www.anttirt.net/2007/08/19/proper-floating-point-comparisons/

AreAlmostEqualUlps ( float left, float right, int maxUlps ) : bool

Compares two floating point values for equality

Floating point values can only represent a finite subset of natural numbers. For example, the values 2.00000000 and 2.00000024 can be stored in a float, but nothing inbetween them.

This comparison will count how many possible floating point values are between the left and the right number. If the number of possible values between both numbers is less than or equal to maxUlps, then the numbers are considered as being equal.

Implementation partially follows the code outlined here: http://www.anttirt.net/2007/08/19/proper-floating-point-comparisons/

ReinterpretAsDouble ( long value ) : double

Reinterprets the memory contents of an integer value as a double precision floating point value

ReinterpretAsFloat ( int value ) : float

Reinterprets the memory contents of an integer as a floating point value

ReinterpretAsInt ( float value ) : int

Reinterprets the memory contents of a floating point value as an integer value

ReinterpretAsLong ( double value ) : long

Reinterprets the memory contents of a double precision floating point value as an integer value

Private Methods

Method Description
FloatingPointNumerics ( ) : System

Method Details

AreAlmostEqualUlps() public static method

Compares two double precision floating point values for equality

Double precision floating point values can only represent a limited series of natural numbers. For example, the values 2.0000000000000000 and 2.0000000000000004 can be stored in a double, but nothing inbetween them.

This comparison will count how many possible double precision floating point values are between the left and the right number. If the number of possible values between both numbers is less than or equal to maxUlps, then the numbers are considered as being equal.

Implementation partially follows the code outlined here: http://www.anttirt.net/2007/08/19/proper-floating-point-comparisons/

public static AreAlmostEqualUlps ( double left, double right, long maxUlps ) : bool
left double First double precision floating point value to be compared
right double Second double precision floating point value t be compared
maxUlps long /// Maximum number of representable double precision floating point values that are /// allowed to be between the left and the right double precision floating point values ///
return bool

AreAlmostEqualUlps() public static method

Compares two floating point values for equality

Floating point values can only represent a finite subset of natural numbers. For example, the values 2.00000000 and 2.00000024 can be stored in a float, but nothing inbetween them.

This comparison will count how many possible floating point values are between the left and the right number. If the number of possible values between both numbers is less than or equal to maxUlps, then the numbers are considered as being equal.

Implementation partially follows the code outlined here: http://www.anttirt.net/2007/08/19/proper-floating-point-comparisons/

public static AreAlmostEqualUlps ( float left, float right, int maxUlps ) : bool
left float First floating point value to be compared
right float Second floating point value t be compared
maxUlps int /// Maximum number of representable floating point values that are allowed to /// be between the left and the right floating point values ///
return bool

ReinterpretAsDouble() public static method

Reinterprets the memory contents of an integer value as a double precision floating point value
public static ReinterpretAsDouble ( long value ) : double
value long Integer whose memory contents to reinterpret
return double

ReinterpretAsFloat() public static method

Reinterprets the memory contents of an integer as a floating point value
public static ReinterpretAsFloat ( int value ) : float
value int Integer value whose memory contents to reinterpret
return float

ReinterpretAsInt() public static method

Reinterprets the memory contents of a floating point value as an integer value
public static ReinterpretAsInt ( float value ) : int
value float /// Floating point value whose memory contents to reinterpret ///
return int

ReinterpretAsLong() public static method

Reinterprets the memory contents of a double precision floating point value as an integer value
public static ReinterpretAsLong ( double value ) : long
value double /// Double precision floating point value whose memory contents to reinterpret ///
return long