/// <summary> /// Returns the absolute value of a <see cref="Posit32"/> 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="Posit32"/> number, x, such that 0 ≤ x ≤ MaxValue.</returns> public static Posit32 Abs(Posit32 x) { unchecked { const int CHAR_BIT = 8; // http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs var mask = (int)x.ui >> sizeof(uint) * CHAR_BIT - 1; var result = ((int)x.ui ^ mask) - mask; return(new Posit32(result)); } }
/// <summary> /// Returns an integer that indicates the sign of a <see cref="Posit32"/> 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(Posit32 x) { if ((x.ui & ~Posit32.SignMask) == 0) { return(0); // Zero or NaR } if ((x.ui & Posit32.SignMask) != 0) { return(-1); // Negative } return(1); }
public DebugProxy(Posit32 value) : this(value.ui, Posit32.nbits, Posit32.es) { }
/// <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 Posit32 Sqrt(Posit32 x) { return(p32_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 Posit32 CopySign(Posit32 x, Posit32 y) { return(((x.ui ^ y.ui) & Posit32.SignMask) == 0 ? x : -x); }
public static bool IsZeroOrNaR(Posit32 p) { return((p.ui & (Posit32.SignMask - 1)) == 0); }
public static bool IsNegative(Posit32 p) => (int)p.ui < 0;
public static bool IsInfinity(Posit32 p) => p.ui == Posit32.Infinity.ui;
public static bool IsNaR(Posit32 p) => p.ui == Posit32.NaR.ui;
public static bool IsOne(Posit32 p) => p.ui == Posit32.One.ui;
public static bool IsZero(Posit32 p) => p.ui == Posit32.Zero.ui;