/// <summary> /// Returns the absolute value of a <see cref="Posit16"/> number. /// </summary> /// <param name="x">A number that is greater than or equal to MinValue, but less than or equal to MaxValue.</param> /// <returns>A <see cref="Posit16"/> number, x, such that 0 ≤ x ≤ MaxValue.</returns> public static Posit16 Abs(Posit16 x) { unchecked { const int CHAR_BIT = 8; // http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs var mask = (short)x.ui >> sizeof(ushort) * CHAR_BIT - 1; var result = (x.ui ^ mask) - mask; return(new Posit16((ushort)result)); } }
/// <summary> /// Returns an integer that indicates the sign of a <see cref="Posit16"/> number. /// </summary> /// <param name="x">A signed number.</param> /// <returns>A number that indicates the sign of <paramref name="x"/></returns> public static int Sign(Posit16 x) { if ((x.ui & ~Posit16.SignMask) == 0) { return(0); // Zero or NaR } if ((x.ui & Posit16.SignMask) != 0) { return(-1); // Negative } return(1); }
/// <summary> /// Returns the square root of a specified number. /// </summary> /// <param name="x">The number whose square root is to be found.</param> /// <returns>One of the values in the following table. /// <list type="table"> /// <listheader> /// <term><paramref name="x"/> parameter</term> /// <term>Return value</term> /// </listheader> /// <item> /// <term>Zero or positive</term> /// <term>The positive square root of <paramref name="x"/>.</term> /// </item> /// <item> /// <term>Negative</term> /// <term>NaR</term> /// </item> /// <item> /// <term>NaR</term> /// <term>NaR</term> /// </item> /// </list> /// </returns> public static Posit16 Sqrt(Posit16 x) { return(p16_sqrt(x)); }
/// <summary> /// Returns a value with the magnitude of <paramref name="x"/> and the sign of <paramref name="y"/>. /// </summary> /// <param name="x">A number whose magnitude is used in the result.</param> /// <param name="y">A number whose sign is the used in the result.</param> /// <returns>A value with the magnitude of <paramref name="x"/> and the sign of <paramref name="y"/>.</returns> public static Posit16 CopySign(Posit16 x, Posit16 y) { return(((x.ui ^ y.ui) & Posit16.SignMask) == 0 ? x : -x); }
public static bool IsNegative(Posit16 p) => (short)p.ui < 0;
public static bool IsZeroOrNaR(Posit16 p) { return((p.ui & (Posit16.SignMask - 1)) == 0); }
public static bool IsInfinity(Posit16 p) => p.ui == Posit16.Infinity.ui;
public static bool IsNaR(Posit16 p) => p.ui == Posit16.NaR.ui;
public static bool IsOne(Posit16 p) => p.ui == Posit16.One.ui;
public static bool IsZero(Posit16 p) => p.ui == Posit16.Zero.ui;
public DebugProxy(Posit16 value) : this(value.ui, Posit16.nbits, Posit16.es) { }