Skip to content

Commit f7ab555

Browse files
author
Barys Chupryn
committed
Initial OpenSource release
1 parent 05943e8 commit f7ab555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+9392
-2
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
# Default settings for all file types.
4+
[*]
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
# Settings for C# source files.
12+
[*.cs]
13+
indent_style = tab
14+

.gitattributes

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
gradlew text eol=lf
2+
gradle.properties text
3+
*.cmd text eol=crlf
4+
*.cs text diff=csharp
5+
*.gradle text
6+
*.cake text diff=csharp
7+
*.vcproj text
8+
*.vcxproj text
9+
*.csproj text
10+
*.vcxproj.user text
11+
*.vcxproj.filters text
12+
*.wixproj text
13+
*.wxs text
14+
*.sln text
15+
*.cfg text
16+
*.yml text

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.vs/
2+
.idea/
3+
.gradle/
4+
*.VC.db
5+
*.user
6+
build/
7+
out/
8+
bin/
9+
obj/
10+
csharp/tools
11+
!csharp/tools/packages.config
12+
artifacts/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "NativeUtils"]
2+
path = NativeUtils
3+
url = https://github.com/deltixlab/NativeUtils.git

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Legal
2+
3+
By submitting a pull request, you represent that you have the right to license
4+
your contribution to Deltix and the community, and agree by submitting the patch
5+
that your contributions are licensed under the Apache 2.0 license.

NativeUtils

Submodule NativeUtils added at 510ce3c

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
Decimal floating point library for java and .net based on intel IEE64 implementation.
2-
Contains packed native libraries for linux, windows and mac.
1+
# Decimal Floating Point Arithmetic for Java/.NET
2+
3+
## Description/Usage
4+
### *TODO*
5+
6+
7+
## Building from source
8+
Note that you need to build native libraries for your target platform(s) before you can build platform-agnostic libraries for Java / .NET.
9+
\
10+
If you want to be able to target Windows, Linux, Mac OS simultaneously, you must build the native libraries on all 3 platforms before building Java / .NET libraries that wrap them together. This is typically done with a CI script that is currently not present in this release.
11+
\
12+
Native libraries can be built for a single OS only but then the resulting Java / .NET libraries will only work on that OS as well..
13+
\
14+
You may build the Java/.NET libraries on a different platform than the one that was used to build native libraries.
15+
16+
### Requirements
17+
+ Intel C compiler at for one of the supported platforms at least (Windows, Linux, Mac OS).
18+
+ zstandard command line compressor
19+
+ Java version: OpenJDK 8+ or Oracle JDK 8+, Gradle build tool
20+
+ .NET Version: .NET Framework 4.0+ or .NET Core or Mono runtime supporting .NET Standard 2.0, Cake build tool
21+
+ Invoking Cake on non-Windows systems may require Mono runtime.
22+
23+
### Fetch the source code
24+
```
25+
git clone --recurse-submodules https://github.com/deltixlab/DFP
26+
cd DFP
27+
```
28+
Note that the current open source release uses (https://github.com/deltixlab/NativeUtils) as a submodule for building both versions of the library(Java and C#).
29+
30+
### Building native resources
31+
The build tasks for native libraries reside in the common Cake script in `csharp` directory for convenience. It is possible to build them without Cake, or change the source code to work without Intel C compiler, but this is left as an exercise for the reader.
32+
#### Windows
33+
From `/csharp` subdirectory:
34+
```
35+
powershell -file build.ps1 --target BuildAndCompressNativeWindowsLibs
36+
```
37+
#### Linux/Mac OS
38+
From `/csharp` subdirectory:
39+
```
40+
sh ./build.sh --target BuildAndCompressNativeLinuxLibs
41+
```
42+
43+
### Building Java library
44+
After building and compressing native libraries as described above, from project root directory:
45+
```
46+
./gradlew shadowJar
47+
```
48+
The build product (standalone JAR library) will appear in `/java/build/libs`
49+
50+
### Building .NET library
51+
After building and compressing native libraries as described above, from `csharp` directory, assuming Windows OS:
52+
```
53+
powershell -file build.ps1
54+
```
55+
Versions for .NET4.0 & .NET Standard 2.0 will appear in `/csharp/Deltix.DFP/bin/Release`
56+
57+
## License
58+
This library is released under Apache 2.0 license. See ([license](LICENSE))

build.gradle

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using BenchmarkDotNet.Attributes;
3+
using BenchmarkDotNet.Attributes.Columns;
4+
using BenchmarkDotNet.Attributes.Exporters;
5+
using BenchmarkDotNet.Attributes.Jobs;
6+
using BenchmarkDotNet.Running;
7+
8+
namespace Deltix.DFP.Benchmark
9+
{
10+
[ClrJob(isBaseline: true), CoreJob]
11+
[RPlotExporter, RankColumn]
12+
public class Benchmark
13+
{
14+
private Decimal64 a1, b1;
15+
private Decimal a2, b2;
16+
17+
[GlobalSetup]
18+
public void Setup()
19+
{
20+
Random random = new Random();
21+
Double a = random.NextDouble();
22+
Double b = random.NextDouble();
23+
a1 = Decimal64.FromDouble(a);
24+
b1 = Decimal64.FromDouble(b);
25+
a2 = (Decimal) a;
26+
b2 = (Decimal) b;
27+
}
28+
29+
[Benchmark]
30+
public Decimal64 AddDecimal64()
31+
{
32+
return a1 + b1;
33+
}
34+
35+
[Benchmark]
36+
public Decimal AddSystem()
37+
{
38+
return a2 + b2;
39+
}
40+
41+
[Benchmark]
42+
public Decimal64 MultiplyDecimal64()
43+
{
44+
return a1 * b1;
45+
}
46+
47+
[Benchmark]
48+
public Decimal MultiplySystem()
49+
{
50+
return a2 * b2;
51+
}
52+
53+
[Benchmark]
54+
public Decimal64 DivisionDecimal64()
55+
{
56+
return a1 / b1;
57+
}
58+
59+
[Benchmark]
60+
public Decimal DivisionSystem()
61+
{
62+
return a2 / b2;
63+
}
64+
65+
public static void Main(String[] args)
66+
{
67+
var summary = BenchmarkRunner.Run<Benchmark>();
68+
}
69+
}
70+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
5+
<AssemblyName>Deltix.DFP.Benchmark</AssemblyName>
6+
<RootNamespace>Deltix.DFP.Benchmark</RootNamespace>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="BenchmarkDotNet" Version="0.10.13" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<ProjectReference Include="..\Deltix.DFP\Deltix.DFP.csproj" />
14+
</ItemGroup>
15+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFrameworks>netcoreapp2.0;net40</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
6+
<RootNamespace>Deltix.DFP.Demo</RootNamespace>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="..\Deltix.DFP\Deltix.DFP.csproj" />
10+
</ItemGroup>
11+
</Project>

csharp/Deltix.DFP.Demo/Program.cs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace Deltix.DFP
5+
{
6+
public class SimpleBenchmark
7+
{
8+
public static void Run()
9+
{
10+
//const int N = 8000000;
11+
//const int M = 30;
12+
//Stopwatch t = new Stopwatch();
13+
//double Best = 1E99, Total = 0;
14+
//long y = 0; // dummy value
15+
//for (int j = 0; j < M; ++j)
16+
//{
17+
// long x = (y & 2) | 1;
18+
// t.Restart();
19+
// for (int i = 0; i < N; ++i)
20+
// {
21+
// x = (Int64)NativeImpl.fromInt64(x) & 0xF | 1;
22+
// }
23+
// t.Stop();
24+
// if (t.Elapsed.TotalSeconds < Best)
25+
// {
26+
// Best = t.Elapsed.TotalSeconds;
27+
// y = x;
28+
// }
29+
30+
// Total += t.Elapsed.TotalSeconds;
31+
//}
32+
33+
//Console.WriteLine("Time Elapsed: " + Total + " s Iteration cost: " + 1.0E9 / N * Best + " ns");
34+
//Console.WriteLine(y);
35+
}
36+
}
37+
}
38+
39+
namespace Deltix.DFP.Demo
40+
{
41+
class Program
42+
{
43+
//
44+
static Decimal ToDecimal(Decimal64 x)
45+
{
46+
return (Decimal)x.ToDouble();
47+
}
48+
49+
static Decimal64 ToDfp64(Decimal x)
50+
{
51+
return Decimal64.FromDouble((double)x);
52+
}
53+
54+
static void TestToString()
55+
{
56+
for (int i = 0; i <= 10; ++i)
57+
Console.WriteLine(Decimal64.FromFixedPoint(0, -i));
58+
59+
for (int i = 1; i <= 10; ++i)
60+
Console.WriteLine(Decimal64.FromFixedPoint(0, i));
61+
62+
for (int i = 0; i <= 10; ++i)
63+
Console.WriteLine(Decimal64.FromFixedPoint(12, -i));
64+
65+
for (int i = 1; i <= 10; ++i)
66+
Console.WriteLine(Decimal64.FromFixedPoint(12, i));
67+
68+
for (int i = 0; i <= 10; ++i)
69+
Console.WriteLine(Decimal64.FromFixedPoint(12000, i));
70+
71+
for (int i = 0; i <= 16; ++i)
72+
Console.WriteLine(Decimal64.FromFixedPoint(9999999999999999, i));
73+
74+
75+
Console.WriteLine(Decimal64.FromFixedPoint(9999999999999999, 383));
76+
Console.WriteLine(Decimal64.FromFixedPoint(9999999999999999, -369));
77+
Console.WriteLine("------");
78+
Console.WriteLine((-1.0 / 0.0).ToString(System.Globalization.CultureInfo.InvariantCulture));
79+
Console.WriteLine((-0.0 / 0.0).ToString(System.Globalization.CultureInfo.InvariantCulture));
80+
Console.WriteLine(Decimal64.PositiveInfinity);
81+
Console.WriteLine(Decimal64.NegativeInfinity);
82+
Console.WriteLine(Decimal64.NaN);
83+
Console.WriteLine(-Decimal64.NaN);
84+
85+
Console.WriteLine("Dfp64.MAX: " + Decimal64.MaxValue);
86+
Console.WriteLine("strlen(Dfp64.MAX): " + Decimal64.MaxValue.ToString().Length);
87+
Console.WriteLine("Dfp64.MIN: " + Decimal64.MinValue);
88+
Console.WriteLine("strlen(Dfp64.MIN): " + Decimal64.MinValue.ToString().Length);
89+
Console.WriteLine("------");
90+
}
91+
92+
static void TestOldDecimal()
93+
{
94+
Decimal64 x = Decimal64.FromULong(1234567890123451);
95+
Decimal64 y = Decimal64.FromDouble(1234567890123455);
96+
97+
Console.WriteLine("Dfp64 x(intended): " + 1234567890123451);
98+
Console.WriteLine("Dfp64 y(intended): " + 1234567890123455);
99+
Console.WriteLine("Dfp64 x: " + x);
100+
Console.WriteLine("Dfp64 y: " + y);
101+
Console.WriteLine("Dfp64 x.ToDecimal(): " + x.ToDecimal());
102+
Console.WriteLine("Dfp64 y.ToDecimal(): " + y.ToDecimal());
103+
104+
Console.WriteLine(ToDecimal(x));
105+
Console.WriteLine(ToDecimal(y));
106+
107+
Console.WriteLine("x - y: " + x.Subtract(y));
108+
109+
x = x.ScaleByPowerOfTen(10);
110+
y = y.ScaleByPowerOfTen(10);
111+
Console.WriteLine("x *= 1E10; y *= 1E10; ");
112+
113+
Console.WriteLine("Dfp64 x: " + x);
114+
Console.WriteLine("Dfp64 y: " + y);
115+
Console.WriteLine("Dfp64 x.ToDecimal(): " + x.ToDecimal());
116+
Console.WriteLine("Dfp64 y.ToDecimal(): " + y.ToDecimal());
117+
Console.WriteLine("x - y: " + x.Subtract(y));
118+
119+
Console.WriteLine("x *= -1E20; y *= -1E30; ");
120+
x = x.ScaleByPowerOfTen(-20);
121+
y = y.ScaleByPowerOfTen(-20);
122+
123+
Console.WriteLine("Dfp64 x: " + x);
124+
Console.WriteLine("Dfp64 y: " + y);
125+
Console.WriteLine("Dfp64 x.ToDecimal(): " + x.ToDecimal());
126+
Console.WriteLine("Dfp64 y.ToDecimal(): " + y.ToDecimal());
127+
Console.WriteLine("x - y: " + x.Subtract(y));
128+
129+
Console.WriteLine("x *= -1E10; y *= -1E10; ");
130+
x = x.ScaleByPowerOfTen(-10);
131+
y = y.ScaleByPowerOfTen(-10);
132+
133+
Console.WriteLine("Dfp64 x: " + x);
134+
Console.WriteLine("Dfp64 y: " + y);
135+
Console.WriteLine("Dfp64 x.ToDecimal(): " + x.ToDecimal());
136+
Console.WriteLine("Dfp64 y.ToDecimal(): " + y.ToDecimal());
137+
Console.WriteLine("x - y: " + x.Subtract(y));
138+
}
139+
140+
static void Main(string[] args)
141+
{
142+
//TestToString();
143+
//TestOldDecimal();
144+
SimpleBenchmark.Run();
145+
Double binary64 = new Random().NextDouble();
146+
Decimal64 decimal64 = Decimal64.FromDouble(binary64);
147+
Console.WriteLine(decimal64);
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)