Infinite Value Public API
InfVal
namespace: InfiniteValue
The main structure of the asset. It represent a value with practically infinite size and precision.
Constructors
InfVal Initializes a new instance of the InfVal structure.
public InfVal()
Initializes a new InfVal with digits and exponent set to 0.
public InfVal(in InfVal value, int? precision = null)
public InfVal(in BigInteger value, int? precision = null)
public InfVal(sbyte value, int? precision = null)
public InfVal(byte value, int? precision = null)
public InfVal(short value, int? precision = null)
public InfVal(ushort value, int? precision = null)
public InfVal(int value, int? precision = null)
public InfVal(uint value, int? precision = null)
public InfVal(long value, int? precision = null)
public InfVal(ulong value, int? precision = null)
public InfVal(float value, int? precision = null)
public InfVal(double value, int? precision = null)
public InfVal(decimal value, int? precision = null)
Initializes a new InfVal using the given value.
Optionnaly set the precision of the InfVal instance by passing an int as the last argument. This will do the same thing as calling ToPrecision.
If you don’t define a precision it will be the number of digits in the given value, except for float, double and decimal which will have a default precision of 9, 17, and 29.
public InfVal(string valStr, int? precision = null)
Initializes a new InfVal using a number string representation. This will use the ParseOrDefault method.
Optionnaly set the precision of the InfVal instance by passing an int as the last argument. This will do the same thing as calling ToPrecision.
If you don’t define a precision it will be the number of digits in the given string, including 0 at the end after the decimal point.
static Methods
ManualFactory Initializes a new InfVal by providing its fields directly.
public static InfVal ManualFactory(in BigInteger digits, int exponent)
Return a new InfVal by providing it’s fields directly.
This isn’t the same as using new InfVal(BigInteger, int).
This method is mostly used internally and you may never have to use it.
Parse Converts the string representation of a number to its InfVal equivalent with exceptions.
public static InfVal Parse(string s)
public static InfVal Parse(string s, string[] unitsList)
public static InfVal Parse(string s, IFormatProvider provider)
public static InfVal Parse(string s, string[] unitsList, IFormatProvider provider)
Converts the string representation of a number to its InfVal equivalent.
This will throw an exception if the string isn’t a valid number.
Check the documentation for more information.
TryParse Converts the string representation of a number to its InfVal equivalent and return wether it succeeded.
public static bool TryParse(string s, out InfVal result)
public static bool TryParse(string s, string[] unitsList, out InfVal result)
public static bool TryParse(string s, IFormatProvider provider, out InfVal result)
public static bool TryParse(string s, string[] unitsList, IFormatProvider provider, out InfVal result)
Converts the string representation of a number to its InfVal equivalent.
This won’t throw an exception but the returned bool indicates whether the operation succeeded.
Check the documentation for more information.
ParseOrDefault Converts the string representation of a number to its InfVal equivalent without exceptions.
public static InfVal ParseOrDefault(string s)
public static InfVal ParseOrDefault(string s, string[] unitsList)
public static InfVal ParseOrDefault(string s, IFormatProvider provider)
public static InfVal ParseOrDefault(string s, string[] unitsList, IFormatProvider provider)
Converts the string representation of a number to its InfVal equivalent.
his won’t throw an exception, if the string isn’t a valid number the method will do it’s best to return a valid InfVal.
Check the documentation for more information.
Properties
digits The full digits that are multiplied by 10 raised to the exponent to get the value.
public BigInteger digits { get; }
Digits of this InfVal.
value = digits x 10exponent
exponent The exponent that 10 is raised by and multiplied by the digits to get the value.
public int exponent { get; }
Exponent of this InfVal.
value = digits x 10exponent
precision Count of digits of this InfVal.
public int precision { get; }
Count of digits of this InfVal.
Cannot be zero or negative.
isInteger Is this InfVal an integer value.
public bool isInteger { get; }
Is this InfVal an integer value.
Can be true with a negative exponent if every digits after the decimal point are 0.
isZero Is this InfVal equal to 0.
public bool isZero { get; }
Is this InfVal equal to 0.
isOne Is this InfVal equal to 1.
public bool isOne { get; }
Is this InfVal equal to 1.
isEven Is this InfVal an even number.
public bool isEven { get; }
Is this InfVal an even number.
Will throw an exception if exponent is negative.
isPowerOfTwo Is this InfVal 2 to an integer power.
public bool isPowerOfTwo { get; }
Is this InfVal 2 to an integer power.
Will never be true if exponent is strictly positive.
Can be true if exponent is negative
sign The sign of this InfVal: 1, 0 or -1.
public bool sign { get; }
The sign of this InfVal.
1 if it is strictly positive, 0 if it is zero and -1 if it is strictly negative.
Methods
ToExponent Return this InfVal with a modified exponent.
public InfVal ToExponent(int exponent, bool raw = false)
Return this InfVal with a modified exponent.
The default behaviour is to add zeros at the end of the digits if you decrease the exponent or trim ending digits if you increase the exponent.
You can optionally set the exponent directly without changing the digits by sending true as the last argument.
ToDigits Return this InfVal with modified digits.
public InfVal ToDigits(in BigInteger digits)
Return this InfVal with modified digits.
ToPrecision Return this InfVal with a modified precision.
public InfVal ToPrecision(int precision)
Return this InfVal with a modified precision by changing the exponent.
This will throw an exception if precision is negative or zero.
RemoveTrailingZeros Return this InfVal with all zeros at the end of the digits removed.
public InfVal RemoveTrailingZeros()
Return this InfVal with all zeros at the end of the digits removed and the exponent modified accordingly.
This wont change the InfVal value.
MovePointLeft Return this InfVal with the decimal point moved left.
public InfVal MovePointLeft(int move)
Return this InfVal with the decimal point moved left by move amount.
This will change the exponent without changing the digits and therefore will change the InfVal value.
MovePointRight Return this InfVal with the decimal point moved right.
public InfVal MovePointRight(int move)
Return this InfVal with the decimal point moved right by move amount.
This will change the exponent without changing the digits and therefore will change the InfVal value.
Deconstruct Extract the digits and exponent of this InfVal.
public void Deconstruct(out BigInteger digits, out int exponent)
Extract the digits and exponent of this InfVal.
Like every Deconstruct method with a similar signature, it can be used by doing:
(BigInteger d, int e) = infValVariable;
ToDebugString Returns a string detailing the digits and exponent of this InfVal.
public string ToDebugString()
Returns a string detailing the digits and exponent of this InfVal, useful for debugging purposes.
The returned string will be in the format:
(digits, exponent)
ToString Converts the numeric value of this instance to its equivalent string representation.
public override string ToString()
public string ToString(IFormatProvider provider)
public string ToString(string format, IFormatProvider provider = null)
public string ToString(int maxDisplayedDigits, IFormatProvider provider = null)
public string ToString(string[] unitsList, IFormatProvider provider = null)
public string ToString(DisplayOption displayOptions, IFormatProvider provider = null)
public string ToString(int maxDisplayedDigits, string[] unitsList, IFormatProvider provider = null)
public string ToString(int maxDisplayedDigits, DisplayOption displayOptions, IFormatProvider provider = null)
public string ToString(string[] unitsList, DisplayOption displayOptions, IFormatProvider provider = null)
public string ToString(int maxDisplayedDigits, string[] unitsList, DisplayOption displayOptions, IFormatProvider provider = null)
Converts the numeric value of this instance to its equivalent string representation.
Check the documentation for more information.
Equals Returns a value indicating whether this instance is equal to another object.
public override bool Equals(object obj)
public bool Equals(InfVal other)
Returns a value indicating whether this instance is equal to another object.
CompareTo Compares this instance to a specified object and returns an indication of their relative values.
public int CompareTo(object obj)
public int CompareTo(InfVal other)
Compares this instance to a specified object and returns an indication of their relative values. This is useful when sorting values.
It will return a value less than zero if this instance precedes the argument in the sort order, zero if if it occurs in the same position as the argument and a value greater than zero is this instance follows the argument in the sort order.
If you use this method with an object, it will throw an exception if it cannot be converted to an InfVal.
GetHashCode Returns the hash code for this instance.
public override int GetHashCode()
Returns the hash code for this instance.
This is used for example by a Dictionary.
OnBeforeSerialize, OnAfterDeserialize Serialization.
public void OnBeforeSerialize()
public void OnAfterDeserialize()
These two methods are automatically called by Unity when serializing an InfVal.
You should never call these methods in your scripts.
If for some reasons you need to call it on an argument, do not use the in keyword.
Operators
Unary +, -, ~, ++, – –
public static InfVal operator +(in InfVal iv)
Returns an InfVal without any changes.
public static InfVal operator -(in InfVal iv)
Returns an InfVal with the sign inverted.
public static InfVal operator ~(in InfVal iv)
Returns the binary ones complement of an InfVal.
This will throw an exception if the InfVal exponent is not zero.
public static InfVal operator ++(in InfVal iv)
Returns an InfVal incremented by one.
public static InfVal operator – – (in InfVal iv)
Returns an InfVal decremented by one.
Binary +, -, *, /, %, &, |, ^, <<, >>
public static InfVal operator +(in InfVal a, in InfVal b)
Add two InfVal. The result precision will be the highest of the two arguments.
public static InfVal operator -(in InfVal a, in InfVal b)
Subtract two InfVal. The result precision will be the highest of the two arguments.
public static InfVal operator *(in InfVal a, in InfVal b)
Multiply two InfVal. The result precision will be the highest of the two arguments.
public static InfVal operator /(in InfVal a, in InfVal b)
Divide an InfVal by another. The result precision will be the highest of the two arguments.
Will throw an exception if b is zero.
public static InfVal operator %(in InfVal a, in InfVal b)
Modulo an InfVal by another. The result precision will be the highest of the two arguments.
Will throw an exception if b is zero.
public static InfVal operator &(in InfVal a, in InfVal b)
Apply the binary AND operator to two InfVal.
Will throw an exception if a or b exponent is not zero.
public static InfVal operator |(in InfVal a, in InfVal b)
Apply the binary OR operator to two InfVal.
Will throw an exception if a or b exponent is not zero.
public static InfVal operator ^(in InfVal a, in InfVal b)
Apply the binary XOR operator to two InfVal.
Will throw an exception if a or b exponent is not zero.
public static InfVal operator <<(in InfVal iv, int decal)
Shift the bits of an InfVal on the left by decal amount.
Will throw an exception if iv exponent is not zero.
public static InfVal operator >>(in InfVal iv, int decal)
Shift the bits of an InfVal on the right by decal amount.
Will throw an exception if iv exponent is not zero.
Comparaison ==, !=, <, >, <=, >=
public static bool operator ==(in InfVal a, in InfVal b)
Returns wether two InfVal are equals.
Can returns true for two InfVal with different exponents.
public static bool operator !=(in InfVal a, in InfVal b)
Returns wether two InfVal are differents.
Can returns false for two InfVal with different exponents.
public static bool operator <(in InfVal a, in InfVal b)
Returns wether an InfVal is strictly inferior to another.
public static bool operator >(in InfVal a, in InfVal b)
Returns wether an InfVal is strictly superior to another.
public static bool operator <=(in InfVal a, in InfVal b)
Returns wether an InfVal is inferior or equals to another.
public static bool operator >=(in InfVal a, in InfVal b)
Returns wether an InfVal is superior or equals to another.
Casts
To Cast a value in another type to an InfVal.
public static implicit operator InfVal(in BigInteger value)
public static implicit operator InfVal(sbyte value)
public static implicit operator InfVal(byte value)
public static implicit operator InfVal(short value)
public static implicit operator InfVal(ushort value)
public static implicit operator InfVal(int value)
public static implicit operator InfVal(uint value)
public static implicit operator InfVal(long value)
public static implicit operator InfVal(ulong value)
public static implicit operator InfVal(float value)
public static implicit operator InfVal(double value)
public static implicit operator InfVal(decimal value)
Implicitly cast a value in another type to an InfVal.
public static implicit operator InfVal((InfVal value, int precision) tuple)
public static implicit operator InfVal((BigInteger value, int precision) tuple)
public static implicit operator InfVal((sbyte value, int precision) tuple)
public static implicit operator InfVal((byte value, int precision) tuple)
public static implicit operator InfVal((short value, int precision) tuple)
public static implicit operator InfVal((ushort value, int precision) tuple)
public static implicit operator InfVal((int value, int precision) tuple)
public static implicit operator InfVal((uint value, int precision) tuple)
public static implicit operator InfVal((long value, int precision) tuple)
public static implicit operator InfVal((ulong value, int precision) tuple)
public static implicit operator InfVal((float value, int precision) tuple)
public static implicit operator InfVal((double value, int precision) tuple)
public static implicit operator InfVal((decimal value, int precision) tuple)
Implicitly cast a value in another type to an InfVal and also set its precision. This will do the same thing as calling ToPrecision.
public static explicit operator InfVal(string valStr)
public static explicit operator InfVal((string valStr, int precision) tuple)
Same as the above but using a string that will be parsed using the ParseOrDefault method (explicit only).
From Cast an InfVal to a value in another type.
public static explicit operator BigInteger(in InfVal iv)
public static explicit operator sbyte(in InfVal iv)
public static explicit operator byte(in InfVal iv)
public static explicit operator short(in InfVal iv)
public static explicit operator ushort(in InfVal iv)
public static explicit operator int(in InfVal iv)
public static explicit operator uint(in InfVal iv)
public static explicit operator long(in InfVal iv)
public static explicit operator ulong(in InfVal iv)
public static explicit operator float(in InfVal iv)
public static explicit operator double(in InfVal iv)
public static explicit operator decimal(in InfVal iv)
Explicitly cast an InfVal to a value in another type.
Convert Convert an InfVal to another type using the Convert class.
The InfVal structure can be used with the C# Convert class because it implements explictly the IConvertible interface:
public TypeCode GetTypeCode()
Returns TypeCode.Object.
public bool ToBoolean(IFormatProvider provider)
public char ToChar(IFormatProvider provider)
public byte ToByte(IFormatProvider provider)
public sbyte ToSByte(IFormatProvider provider)
public short ToInt16(IFormatProvider provider)
public ushort ToUInt16(IFormatProvider provider)
public int ToInt32(IFormatProvider provider)
public uint ToUInt32(IFormatProvider provider)
public long ToInt64(IFormatProvider provider)
public ulong ToUInt64(IFormatProvider provider)
public float ToSingle(IFormatProvider provider)
public double ToDouble(IFormatProvider provider)
public decimal ToDecimal(IFormatProvider provider)
Convert an InfVal to a value in another type. The provider is ignored.
public DateTime ToDateTime(IFormatProvider provider)
Always throw an exception.
public object ToType(Type conversionType, IFormatProvider provider)
Convert an InfVal to the type given as an argument. The provider is ignored.
This will throw an exception if an InfVal cannot be converted to the given type.