/// </summary>
public enum Precision
{
+ /// <summary>
+ /// Perform calculations using C "double" type
+ /// </summary>
Double,
+
+ /// <summary>
+ /// Perform calculations using C "long double" type
+ /// </summary>
LongDouble,
+
+ /// <summary>
+ /// Perform calculations using 64-bit fixed point
+ /// </summary>
Fixed64,
+
+ /// <summary>
+ /// Perform calculations using 128-bit fixed point
+ /// </summary>
Fixed128,
};
return new Fixed128(n, 0, 0, 0);
}
+ /// <summary>
+ /// Convert string to fixed-point
+ /// </summary>
+ /// <param name="s">String containing decimal value to convert</param>
+ /// <returns>Value</returns>
+ /// <exception cref="FormatException">Thrown if the value is out of range or malformed.</exception>
public static implicit operator Fixed128(string s)
{
Fixed128 r = 0;
return r;
}
+ /// <summary>
+ /// Convert fixed-point to string
+ /// </summary>
+ /// <param name="n">Value to convert</param>
+ /// <returns>String containing decimal equivalent of value</returns>
public unsafe static implicit operator string(Fixed128 n)
{
const int BUFSIZE = 256;
return Marshal.PtrToStringAnsi((IntPtr)buffer);
}
+ /// <summary>
+ /// Convert fixed-point to double
+ /// </summary>
+ /// <param name="n">Value to convert</param>
+ /// <returns>Converted value</returns>
public static implicit operator double(Fixed128 n)
{
return Fixed128_2double(ref n);
}
+ /// <summary>
+ /// Convert double to fixed-point
+ /// </summary>
+ /// <param name="n">Value to convert</param>
+ /// <returns>Converted value</returns>
public static implicit operator Fixed128(double n)
{
Fixed128 r = 0;
#endregion
#region Arithmetic Operations
-
+
+ /// <summary>
+ /// Add fixed-point values
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns><code>a+b</code></returns>
public static Fixed128 operator +(Fixed128 a, Fixed128 b)
{
Fixed128 r = 0;
return r;
}
+ /// <summary>
+ /// Subtract fixed-point values
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns><code>a-b</code></returns>
public static Fixed128 operator -(Fixed128 a, Fixed128 b)
{
Fixed128 r = 0;
return r;
}
+ /// <summary>
+ /// Multiply fixed-point values
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns><code>a*b</code></returns>
public static Fixed128 operator *(Fixed128 a, Fixed128 b)
{
Fixed128 r = 0;
return r;
}
+ /// <summary>
+ /// Divide fixed-point values
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns><code>a/b</code></returns>
public static Fixed128 operator /(Fixed128 a, Fixed128 b)
{
+ // TODO division by 0?
Fixed128 r = 0;
Fixed128_div(ref r, ref a, ref b);
return r;
}
- public static Fixed128 operator-(Fixed128 a)
+ /// <summary>
+ /// Negate fixed-point value
+ /// </summary>
+ /// <param name="a">Value</param>
+ /// <returns><code>-a</code></returns>
+ public static Fixed128 operator -(Fixed128 a)
{
Fixed128 r = 0;
Fixed128_neg(ref r, ref a);
return r;
}
+ /// <summary>
+ /// Square root fixed-point value
+ /// </summary>
+ /// <returns>Square root of this</returns>
public Fixed128 sqrt()
{
+ // TODO negative values
Fixed128 r = 0;
Fixed128_sqrt(ref r, ref this);
return r;
}
+ /// <summary>
+ /// Compare fixed-point values for equality
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns>true if <code>a==b</code>, else false</returns>
public static bool operator ==(Fixed128 a, Fixed128 b)
{
return Fixed128_eq(ref a, ref b) != 0;
}
+ /// <summary>
+ /// Compare fixed-point values for inequality
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns>true if <code>a!=b</code>, else false</returns>
public static bool operator !=(Fixed128 a, Fixed128 b)
{
return Fixed128_eq(ref a, ref b) == 0;
}
+ /// <summary>
+ /// Compare fixed-point values for order
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns>true if <code>a<b</code>, else false</returns>
public static bool operator <(Fixed128 a, Fixed128 b)
{
return Fixed128_lt(ref a, ref b) != 0;
}
+ /// <summary>
+ /// Compare fixed-point values for order
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns>true if <code>a>=b</code>, else false</returns>
public static bool operator >=(Fixed128 a, Fixed128 b)
{
return Fixed128_lt(ref a, ref b) == 0;
}
+ /// <summary>
+ /// Compare fixed-point values for order
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns>true if <code>a>b</code>, else false</returns>
public static bool operator >(Fixed128 a, Fixed128 b)
{
return Fixed128_lt(ref b, ref a) != 0;
}
+ /// <summary>
+ /// Compare fixed-point values for order
+ /// </summary>
+ /// <param name="a">First value</param>
+ /// <param name="b">Second value</param>
+ /// <returns>true if <code>a<=b</code>, else false</returns>
public static bool operator <=(Fixed128 a, Fixed128 b)
{
return Fixed128_lt(ref b, ref a) == 0;
#region Algorithms
+ /// <summary>
+ /// Calculate Mandelbrot set iteration
+ /// </summary>
+ /// <param name="zx">Starting real part</param>
+ /// <param name="zy">Starting imaginary part</param>
+ /// <param name="cx">Offset constant real part</param>
+ /// <param name="cy">Offset constant imaginary part</param>
+ /// <param name="maxiters">Maximum number of iterations</param>
+ /// <param name="precision">Precision to use</param>
+ /// <returns>Adjusted iteration count</returns>
public static double iterate(Fixed128 zx, Fixed128 zy,
Fixed128 cx, Fixed128 cy,
int maxiters, Precision precision)