示例#1
0
 /// <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));
     }
 }
示例#2
0
 /// <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);
 }
示例#3
0
 /// <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));
 }
示例#4
0
 /// <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);
 }
示例#5
0
 public static bool IsNegative(Posit16 p) => (short)p.ui < 0;
示例#6
0
 public static bool IsZeroOrNaR(Posit16 p)
 {
     return((p.ui & (Posit16.SignMask - 1)) == 0);
 }
示例#7
0
 public static bool IsInfinity(Posit16 p) => p.ui == Posit16.Infinity.ui;
示例#8
0
 public static bool IsNaR(Posit16 p) => p.ui == Posit16.NaR.ui;
示例#9
0
 public static bool IsOne(Posit16 p) => p.ui == Posit16.One.ui;
示例#10
0
 public static bool IsZero(Posit16 p) => p.ui == Posit16.Zero.ui;
示例#11
0
 public DebugProxy(Posit16 value)
     : this(value.ui, Posit16.nbits, Posit16.es)
 {
 }