TrueSync
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
TrueSync.FP Struct Reference

Represents a Q31.32 fixed-point number. More...

Inheritance diagram for TrueSync.FP:

Public Member Functions

void OnBeforeSerialize ()
 
void OnAfterDeserialize ()
 
float AsFloat ()
 
int AsInt ()
 
long AsLong ()
 
double AsDouble ()
 
decimal AsDecimal ()
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
bool Equals (FP other)
 
int CompareTo (FP other)
 
override string ToString ()
 
 FP (long rawValue)
 This is the constructor from raw value; it can only be used interally. More...
 
 FP (int value)
 

Static Public Member Functions

static int Sign (FP value)
 Returns a number indicating the sign of a Fix64 number. Returns 1 if the value is positive, 0 if is 0, and -1 if it is negative. More...
 
static FP Abs (FP value)
 Returns the absolute value of a Fix64 number. Note: Abs(Fix64.MinValue) == Fix64.MaxValue. More...
 
static FP FastAbs (FP value)
 Returns the absolute value of a Fix64 number. FastAbs(Fix64.MinValue) is undefined. More...
 
static FP Floor (FP value)
 Returns the largest integer less than or equal to the specified number. More...
 
static FP Ceiling (FP value)
 Returns the smallest integral value that is greater than or equal to the specified number. More...
 
static FP Round (FP value)
 Rounds a value to the nearest integral value. If the value is halfway between an even and an uneven value, returns the even value. More...
 
static FP operator+ (FP x, FP y)
 Adds x and y. Performs saturating addition, i.e. in case of overflow, rounds to MinValue or MaxValue depending on sign of operands. More...
 
static FP FastAdd (FP x, FP y)
 Adds x and y witout performing overflow checking. Should be inlined by the CLR. More...
 
static FP operator- (FP x, FP y)
 Subtracts y from x. Performs saturating substraction, i.e. in case of overflow, rounds to MinValue or MaxValue depending on sign of operands. More...
 
static FP FastSub (FP x, FP y)
 Subtracts y from x witout performing overflow checking. Should be inlined by the CLR. More...
 
static long AddOverflowHelper (long x, long y, ref bool overflow)
 
static FP operator* (FP x, FP y)
 
static FP FastMul (FP x, FP y)
 Performs multiplication without checking for overflow. Useful for performance-critical code where the values are guaranteed not to cause overflow More...
 
static int CountLeadingZeroes (ulong x)
 
static FP operator/ (FP x, FP y)
 
static FP operator% (FP x, FP y)
 
static FP FastMod (FP x, FP y)
 Performs modulo as fast as possible; throws if x == MinValue and y == -1. Use the operator (%) for a more reliable but slower modulo. More...
 
static FP operator- (FP x)
 
static bool operator== (FP x, FP y)
 
static bool operator!= (FP x, FP y)
 
static bool operator> (FP x, FP y)
 
static bool operator< (FP x, FP y)
 
static bool operator>= (FP x, FP y)
 
static bool operator<= (FP x, FP y)
 
static FP Sqrt (FP x)
 Returns the square root of a specified number. More...
 
static FP Sin (FP x)
 Returns the Sine of x. This function has about 9 decimals of accuracy for small values of x. It may lose accuracy as the value of x grows. Performance: about 25% slower than Math.Sin() in x64, and 200% slower in x86. More...
 
static FP FastSin (FP x)
 Returns a rough approximation of the Sine of x. This is at least 3 times faster than Sin() on x86 and slightly faster than Math.Sin(), however its accuracy is limited to 4-5 decimals, for small enough values of x. More...
 
static long ClampSinValue (long angle, out bool flipHorizontal, out bool flipVertical)
 
static FP Cos (FP x)
 Returns the cosine of x. See Sin() for more details. More...
 
static FP FastCos (FP x)
 Returns a rough approximation of the cosine of x. See FastSin for more details. More...
 
static FP Tan (FP x)
 Returns the tangent of x. More...
 
static FP Atan (FP y)
 
static FP Atan2 (FP y, FP x)
 
static FP Asin (FP value)
 
static FP Acos (FP value)
 
static implicit operator FP (long value)
 
static operator long (FP value)
 
static implicit operator FP (float value)
 
static operator float (FP value)
 
static implicit operator FP (double value)
 
static operator double (FP value)
 
static operator FP (decimal value)
 
static implicit operator FP (int value)
 
static operator decimal (FP value)
 
static float ToFloat (FP value)
 
static int ToInt (FP value)
 
static FP FromFloat (float value)
 
static bool IsInfinity (FP value)
 
static bool IsNaN (FP value)
 
static FP FromRaw (long rawValue)
 

Public Attributes

const long MAX_VALUE = long.MaxValue
 
const long MIN_VALUE = long.MinValue
 
const int NUM_BITS = 64
 
const int FRACTIONAL_PLACES = 32
 
const long ONE = 1L << FRACTIONAL_PLACES
 
const long TEN = 10L << FRACTIONAL_PLACES
 
const long HALF = 1L << (FRACTIONAL_PLACES - 1)
 
const long PI_TIMES_2 = 0x6487ED511
 
const long PI = 0x3243F6A88
 
const long PI_OVER_2 = 0x1921FB544
 
const int LUT_SIZE = (int)(PI_OVER_2 >> 15)
 

Static Public Attributes

static readonly decimal Precision = (decimal)(new FP(1L))
 
static readonly FP MaxValue = new FP(MAX_VALUE-1)
 
static readonly FP MinValue = new FP(MIN_VALUE+2)
 
static readonly FP One = new FP(ONE)
 
static readonly FP Ten = new FP(TEN)
 
static readonly FP Half = new FP(HALF)
 
static readonly FP Zero = new FP()
 
static readonly FP PositiveInfinity = new FP(MAX_VALUE)
 
static readonly FP NegativeInfinity = new FP(MIN_VALUE+1)
 
static readonly FP NaN = new FP(MIN_VALUE)
 
static readonly FP EN1 = FP.One / 10
 
static readonly FP EN2 = FP.One / 100
 
static readonly FP EN3 = FP.One / 1000
 
static readonly FP EN4 = FP.One / 10000
 
static readonly FP EN5 = FP.One / 100000
 
static readonly FP EN6 = FP.One / 1000000
 
static readonly FP EN7 = FP.One / 10000000
 
static readonly FP EN8 = FP.One / 100000000
 
static readonly FP Epsilon = FP.EN3
 
static readonly FP Pi = new FP(PI)
 The value of Pi More...
 
static readonly FP PiOver2 = new FP(PI_OVER_2)
 
static readonly FP PiTimes2 = new FP(PI_TIMES_2)
 
static readonly FP PiInv = (FP)0.3183098861837906715377675267M
 
static readonly FP PiOver2Inv = (FP)0.6366197723675813430755350535M
 
static readonly FP Deg2Rad = Pi / new FP(180)
 
static readonly FP Rad2Deg = new FP(180) / Pi
 
static readonly FP LutInterval = (FP)(LUT_SIZE - 1) / PiOver2
 

Properties

long RawValue [get]
 The underlying integer representation More...
 

Detailed Description

Represents a Q31.32 fixed-point number.

Definition at line 11 of file Fix64.cs.

Constructor & Destructor Documentation

TrueSync.FP.FP ( long  rawValue)

This is the constructor from raw value; it can only be used interally.

Parameters
rawValue

Definition at line 823 of file Fix64.cs.

Member Function Documentation

static FP TrueSync.FP.Abs ( FP  value)
static

Returns the absolute value of a Fix64 number. Note: Abs(Fix64.MinValue) == Fix64.MaxValue.

Definition at line 94 of file Fix64.cs.

static FP TrueSync.FP.Ceiling ( FP  value)
static

Returns the smallest integral value that is greater than or equal to the specified number.

Definition at line 126 of file Fix64.cs.

static FP TrueSync.FP.Cos ( FP  x)
static

Returns the cosine of x. See Sin() for more details.

Definition at line 559 of file Fix64.cs.

static FP TrueSync.FP.FastAbs ( FP  value)
static

Returns the absolute value of a Fix64 number. FastAbs(Fix64.MinValue) is undefined.

Definition at line 108 of file Fix64.cs.

static FP TrueSync.FP.FastAdd ( FP  x,
FP  y 
)
static

Adds x and y witout performing overflow checking. Should be inlined by the CLR.

Definition at line 172 of file Fix64.cs.

static FP TrueSync.FP.FastCos ( FP  x)
static

Returns a rough approximation of the cosine of x. See FastSin for more details.

Definition at line 570 of file Fix64.cs.

static FP TrueSync.FP.FastMod ( FP  x,
FP  y 
)
static

Performs modulo as fast as possible; throws if x == MinValue and y == -1. Use the operator (%) for a more reliable but slower modulo.

Definition at line 378 of file Fix64.cs.

static FP TrueSync.FP.FastMul ( FP  x,
FP  y 
)
static

Performs multiplication without checking for overflow. Useful for performance-critical code where the values are guaranteed not to cause overflow

Definition at line 280 of file Fix64.cs.

static FP TrueSync.FP.FastSin ( FP  x)
static

Returns a rough approximation of the Sine of x. This is at least 3 times faster than Sin() on x86 and slightly faster than Math.Sin(), however its accuracy is limited to 4-5 decimals, for small enough values of x.

Definition at line 512 of file Fix64.cs.

static FP TrueSync.FP.FastSub ( FP  x,
FP  y 
)
static

Subtracts y from x witout performing overflow checking. Should be inlined by the CLR.

Definition at line 197 of file Fix64.cs.

static FP TrueSync.FP.Floor ( FP  value)
static

Returns the largest integer less than or equal to the specified number.

Definition at line 118 of file Fix64.cs.

static FP TrueSync.FP.operator+ ( FP  x,
FP  y 
)
static

Adds x and y. Performs saturating addition, i.e. in case of overflow, rounds to MinValue or MaxValue depending on sign of operands.

Definition at line 155 of file Fix64.cs.

static FP TrueSync.FP.operator- ( FP  x,
FP  y 
)
static

Subtracts y from x. Performs saturating substraction, i.e. in case of overflow, rounds to MinValue or MaxValue depending on sign of operands.

Definition at line 180 of file Fix64.cs.

static FP TrueSync.FP.Round ( FP  value)
static

Rounds a value to the nearest integral value. If the value is halfway between an even and an uneven value, returns the even value.

Definition at line 135 of file Fix64.cs.

static int TrueSync.FP.Sign ( FP  value)
static

Returns a number indicating the sign of a Fix64 number. Returns 1 if the value is positive, 0 if is 0, and -1 if it is negative.

Definition at line 82 of file Fix64.cs.

static FP TrueSync.FP.Sin ( FP  x)
static

Returns the Sine of x. This function has about 9 decimals of accuracy for small values of x. It may lose accuracy as the value of x grows. Performance: about 25% slower than Math.Sin() in x64, and 200% slower in x86.

Definition at line 482 of file Fix64.cs.

static FP TrueSync.FP.Sqrt ( FP  x)
static

Returns the square root of a specified number.

Exceptions
ArgumentOutOfRangeExceptionThe argument was negative.

Definition at line 417 of file Fix64.cs.

static FP TrueSync.FP.Tan ( FP  x)
static

Returns the tangent of x.

This function is not well-tested. It may be wildly inaccurate.

Definition at line 582 of file Fix64.cs.

Member Data Documentation

readonly FP TrueSync.FP.Pi = new FP(PI)
static

The value of Pi

Definition at line 56 of file Fix64.cs.

Property Documentation

long TrueSync.FP.RawValue
get
Initial value:
namespace FixMath.NET {
partial struct Fix64 {
public static readonly long[] TanLut = new[] {"
};
}
}"

The underlying integer representation

Definition at line 817 of file Fix64.cs.


The documentation for this struct was generated from the following file: