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