Class XDecimal
Extension methods for decimal.
Inheritance
Namespace: Galaxon.Core.Numbers
Assembly: Galaxon.Core.dll
Syntax
public static class XDecimal : object
Fields
MaxScale
The minimum scale factor (inverse decimal exponent).
Declaration
public const short MaxScale = null
Field Value
| Type | Description |
|---|---|
| System.Int16 |
NumExpBits
The number of bits in the exponent.
Declaration
public const byte NumExpBits = null
Field Value
| Type | Description |
|---|---|
| System.Byte |
NumIntBits
The number of bits in the integer part.
Declaration
public const byte NumIntBits = null
Field Value
| Type | Description |
|---|---|
| System.Byte |
Methods
Acosh(Decimal)
Inverse hyperbolic cosine.
Declaration
public static decimal Acosh(decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x | The hyperbolic cosine of an angle. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The angle. |
Asinh(Decimal)
Inverse hyperbolic sine.
Declaration
public static decimal Asinh(decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x | The hyperbolic sine of an angle. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The angle. |
Assemble(Byte, Byte, UInt128)
Assemble a new decimal value from bitwise parts.
Declaration
public static decimal Assemble(byte signBit, byte scaleBits, UInt128 intBits)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte | signBit | The sign bit (1 or 0). |
| System.Byte | scaleBits | The scale bits. |
| UInt128 | intBits | The integer bits. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The new decimal. |
Atanh(Decimal)
Inverse hyperbolic tangent.
Declaration
public static decimal Atanh(decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x | The hyperbolic tangent of an angle. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The angle. |
Cosh(Decimal)
Hyperbolic cosine.
Declaration
public static decimal Cosh(decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x | The hyperbolic angle. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The hyperbolic cosine of the given angle. |
Disassemble(Decimal)
Disassemble the decimal into bitwise parts.
Declaration
public static (byte signBit, byte scaleBits, UInt128 intBits) Disassemble(this decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x |
Returns
| Type | Description |
|---|---|
| System.ValueTuple<System.Byte, System.Byte, UInt128> |
Exp10(Decimal)
Calculate 10 raised to a decimal power.
Declaration
public static decimal Exp10(decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | A decimal value. |
Returns
| Type | Description |
|---|---|
| System.Decimal | 10^d |
Exp2(Decimal)
Calculate 2 raised to a decimal power.
Declaration
public static decimal Exp2(decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | A decimal value. |
Returns
| Type | Description |
|---|---|
| System.Decimal | 2^d |
GetRandom()
Returns a random decimal.
Declaration
public static decimal GetRandom()
Returns
| Type | Description |
|---|---|
| System.Decimal |
IsInteger(Decimal)
Check if a decimal value is an integer.
Declaration
public static bool IsInteger(decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Log(Decimal)
Calculate the natural logarithm of a decimal.
The algorithm is from:
https://en.wikipedia.org/wiki/Natural_logarithm
I found that DecimalEx.Log() hangs for very small values so I made this version.
It's tested, fast, and doesn't break with the largest or smallest decimal values.
Declaration
public static decimal Log(decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | A decimal value. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The natural logarithm of the given value. |
Log(Decimal, Decimal)
Logarithm of a decimal in a specified base.
Declaration
public static decimal Log(decimal m, decimal b)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | The decimal value. |
| System.Decimal | b | The base. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The logarithm of z in base b. |
Log10(Decimal)
Logarithm of a decimal in base 10.
Declaration
public static decimal Log10(decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | The decimal value. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The logarithm of the number in base 10. |
Log2(Decimal)
Logarithm of a decimal in base 2.
Declaration
public static decimal Log2(decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | The decimal value. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The logarithm of the number in base 2. |
RoundSigFigs(Decimal, Int32)
Round off a value to a given number of significant figures.
Declaration
public static decimal RoundSigFigs(decimal m, int n)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | m | The number to round. |
| System.Int32 | n | The number of significant figures. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The rounded number. |
Sinh(Decimal)
Hyperbolic sine.
Declaration
public static decimal Sinh(decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x | The hyperbolic angle. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The hyperbolic sine of the given angle. |
Tanh(Decimal)
Hyperbolic tangent.
Declaration
public static decimal Tanh(decimal x)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Decimal | x | The hyperbolic angle. |
Returns
| Type | Description |
|---|---|
| System.Decimal | The hyperbolic tangent of the given angle. |