Lightly tested.
abort();
}
}
+
+count_t iterate_cs(const Fixed128 *zx, const Fixed128 *zy,
+ const Fixed128 *cx, const Fixed128 *cy,
+ int maxiters, int arith) {
+ return iterate(fixed128(*zx), fixed128(*zy),
+ fixed128(*cx), fixed128(*cy),
+ maxiters, (arith_type)arith);
+}
\ No newline at end of file
LIBMANDY_API count_t iterate(arith_t zx, arith_t zy, arith_t cx, arith_t cy,
int maxiters, arith_type arith);
+// C#-friendly interface
+extern "C" {
+ LIBMANDY_API count_t iterate_cs(const Fixed128 *zx, const Fixed128 *zy,
+ const Fixed128 *cx, const Fixed128 *cy,
+ int maxiters, int arith);
+}
+
#endif /* ARITH_H */
/*
namespace uk.org.greenend.mandy
{
/// <summary>
+ /// Possible precisions
+ /// </summary>
+ public enum Precision
+ {
+ Double,
+ LongDouble,
+ Fixed64,
+ Fixed128,
+ };
+
+ /// <summary>
/// 128-bit fixed point arithmetic
/// </summary>
/// <remarks><para>You get 32 bits of integer part and 96 bit of fractional part.</para></remarks>
#endregion
- #region Operations
+ #region Arithmetic Operations
public static Fixed128 operator +(Fixed128 a, Fixed128 b)
{
#endregion
+ #region Algorithms
+
+ public static double iterate(Fixed128 zx, Fixed128 zy,
+ Fixed128 cx, Fixed128 cy,
+ int maxiters, Precision precision)
+ {
+ return iterate_cs(ref zx, ref zy, ref cx, ref cy, maxiters, (int)precision);
+ }
+
+ #endregion
+
#region Unmanaged code
[DllImport("libmandy.dll")]
[DllImport("libmandy.dll")]
private static extern double Fixed128_2double(ref Fixed128 a);
+ [DllImport("libmandy.dll")]
+ private static extern double iterate_cs(ref Fixed128 zx, ref Fixed128 zy,
+ ref Fixed128 cx, ref Fixed128 cy,
+ int maxiters, int arith);
+
#endregion
}
--- /dev/null
+\feffusing System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using uk.org.greenend.mandy;
+
+namespace tests
+{
+ [TestClass]
+ public class IterationTest
+ {
+ /// <summary>
+ /// Tests for Fix128
+ /// </summary>
+ /// <remarks>
+ /// <para>Only the 64-bit configuration is testable.</para></remarks>
+ [TestMethod]
+ [DeploymentItem(@"..\..\..\..\x64\Debug\libmandy.dll")]
+ public void IterateTest()
+ {
+ Fixed128 zx = 0, zy = 0;
+ Fixed128 cx = new Fixed128(0, 0xa6aaaaaau, 0xaaaaaaaau, 0xaaaaaaabu);
+ Fixed128 cy = new Fixed128(-1, 0xfd555555u, 0x55555555u, 0x55555555u);
+ Assert.AreEqual("0.651041666666666666666666666670873924827845396295529219014841526558257100987248122692108154296875",
+ (string)cx);
+ Assert.AreEqual("-0.010416666666666666666666666670873924827845396295529219014841526558257100987248122692108154296875",
+ (string)cy);
+ double count = Fixed128.iterate(zx, zy, cx, cy, 255, Precision.Double);
+ double expected = 1 + 5 - Math.Log(Math.Log(255.08471462316811, 2), 2);
+ Assert.AreEqual(count, expected);
+ count = Fixed128.iterate(zx, zy, cx, cy, 255, Precision.LongDouble);
+ Assert.AreEqual(count, expected);
+ count = Fixed128.iterate(zx, zy, cx, cy, 255, Precision.Fixed64);
+ Assert.AreEqual(count, expected);
+ count = Fixed128.iterate(zx, zy, cx, cy, 255, Precision.Fixed128);
+ Assert.AreEqual(count, expected);
+ }
+ }
+}
<Compile Include="JobQueueTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Fixed128Test.cs" />
+ <Compile Include="IterationTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\mandycs\mandycs.csproj">