Skip to content

Commit 489b6ce

Browse files
authored
[DXFC-334] Precision error when converting WideDecimal to Double (#89)
1 parent d87b108 commit 489b6ce

File tree

409 files changed

+100762
-297
lines changed

Some content is hidden

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

409 files changed

+100762
-297
lines changed

.github/workflows/github-ci-pull-req.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,22 @@ env:
1313
BUILD_VERSION: 0.0.0-pr
1414

1515
jobs:
16+
tests:
17+
runs-on: ubuntu-latest
18+
name: build and run tests
19+
steps:
20+
- uses: actions/checkout@main
21+
- name: Test
22+
run: |
23+
mkdir build-test
24+
cd build-test
25+
cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_TLS=ON -DTARGET_PLATFORM=x64 -DDXFC_BUILD_UNIT_TESTS=ON ..
26+
cmake --build . --config Release
27+
ctest -C Release
28+
env:
29+
CTEST_OUTPUT_ON_FAILURE: True
1630

17-
# --------------------------- BUILD DOCUMENTATION
31+
# --------------------------- BUILD DOCUMENTATION
1832
build_docs:
1933
runs-on: ubuntu-latest
2034
name: build documentation

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/**/*.user
66
/**/*.aps
77
/**/build
8+
/**/build-test
89
/*.ncb
910
/*.sdf
1011
/*.opensdf

CMakeLists.txt

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ set(PROJECT DXFeedAll)
77

88
option(DISABLE_TLS "Use ON value to disable TLS support" OFF)
99
option(BUILD_STATIC_LIBS "Use ON value to build dxFeed framework as a static library" OFF)
10+
option(DXFC_BUILD_INTEGRATION_TESTS "" ON)
11+
option(DXFC_BUILD_UNIT_TESTS "" OFF)
1012

1113
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
1214
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
@@ -18,7 +20,7 @@ link_directories(${CMAKE_BINARY_DIR})
1820

1921
if (WIN32 OR MACOS)
2022
set(BUILD_STATIC_LIBS OFF)
21-
endif()
23+
endif ()
2224

2325
if (BUILD_STATIC_LIBS)
2426
set(DISABLE_TLS ON)
@@ -34,27 +36,36 @@ endif (BUILD_STATIC_LIBS)
3436
add_subdirectory(thirdparty/toml11)
3537

3638
#Note: add projects to build and package below
37-
add_subdirectory(src)
38-
39-
add_subdirectory(samples/CandleSample)
40-
add_subdirectory(samples/CommandLineSample)
41-
add_subdirectory(samples/FullOrderBookSample)
42-
add_subdirectory(samples/PriceLevelBookSample)
43-
add_subdirectory(samples/PriceLevelBookSample2)
44-
add_subdirectory(samples/RegionalBookSample)
45-
add_subdirectory(samples/SnapshotConsoleSample)
46-
add_subdirectory(samples/IncSnapshotConsoleSample)
47-
48-
add_subdirectory(wrappers/cpp)
49-
50-
add_subdirectory(tests/FullTest)
51-
52-
add_subdirectory(tests/APITest)
53-
add_subdirectory(tests/ConnectionTest)
54-
add_subdirectory(tests/PerformanceTest)
55-
add_subdirectory(tests/LastEventTest)
56-
add_subdirectory(tests/QuoteTableTest)
57-
add_subdirectory(tests/SampleTest)
39+
40+
if (DXFC_BUILD_UNIT_TESTS)
41+
include(CTest)
42+
add_subdirectory(tests/UnitTests2)
43+
else ()
44+
add_subdirectory(src)
45+
46+
add_subdirectory(samples/CandleSample)
47+
add_subdirectory(samples/CommandLineSample)
48+
add_subdirectory(samples/FullOrderBookSample)
49+
add_subdirectory(samples/PriceLevelBookSample)
50+
add_subdirectory(samples/PriceLevelBookSample2)
51+
add_subdirectory(samples/RegionalBookSample)
52+
add_subdirectory(samples/SnapshotConsoleSample)
53+
add_subdirectory(samples/IncSnapshotConsoleSample)
54+
55+
add_subdirectory(wrappers/cpp)
56+
57+
add_subdirectory(tests/PerformanceTest)
58+
59+
if (DXFC_BUILD_INTEGRATION_TESTS)
60+
add_subdirectory(tests/FullTest)
61+
62+
add_subdirectory(tests/APITest)
63+
add_subdirectory(tests/ConnectionTest)
64+
add_subdirectory(tests/LastEventTest)
65+
add_subdirectory(tests/QuoteTableTest)
66+
add_subdirectory(tests/SampleTest)
67+
endif ()
68+
endif ()
5869

5970
set(CPACK_OUTPUT_CONFIG_FILE "${CMAKE_BINARY_DIR}/DXFeedAllCPackConfig.cmake")
6071
set(CPACK_PACKAGE_VENDOR "Devexperts LLC")

DXFeed.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@
618618
<ClInclude Include="thirdparty\toml11\toml.hpp" />
619619
<ClInclude Include="src\Version.h" />
620620
<ClInclude Include="src\WideDecimal.h" />
621+
<ClInclude Include="src\WideDecimal.hpp" />
621622
</ItemGroup>
622623
<ItemGroup>
623624
<ResourceCompile Include="src\DXFeed.rc" />

DXFeed.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@
333333
<ClInclude Include="src\WideDecimal.h">
334334
<Filter>Header Files</Filter>
335335
</ClInclude>
336+
<ClInclude Include="src\WideDecimal.hpp">
337+
<Filter>Header Files</Filter>
338+
</ClInclude>
336339
</ItemGroup>
337340
<ItemGroup>
338341
<ResourceCompile Include="src\DXFeed.rc" />

README.md

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ This package provides access to **[dxFeed](https://www.dxfeed.com/)** market dat
1010
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/dxFeed/dxfeed-c-api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/dxFeed/dxfeed-c-api/context:cpp)
1111

1212

13-
## Table of Сontents
13+
## Table of Contents
1414
- [Documentation](#documentation)
15+
- [Dependencies](#dependencies)
1516
- [How to build](#how-to-build)
1617
* [Windows](#windows)
1718
* [Linux](#linux)
1819
* [macOS](#macos)
20+
* [Android Termux](#android-termux)
1921
- [Key features](#key-features)
2022
* [Event types](#event-types)
2123
* [Contracts](#contracts)
@@ -54,30 +56,83 @@ Find useful information in self-service dxFeed Knowledge Base, or C API framewor
5456
* [Subscriptions](https://docs.dxfeed.com/c-api/group__c-api-basic-subscription-functions.html)
5557

5658

59+
## Dependencies
5760

61+
- API
62+
- Boost.Locale.EncodingUtf (1.75)
63+
- [TOML11](https://github.com/ToruNiina/toml11) (3.6.0)
64+
- Tests
65+
- [Catch2](https://github.com/catchorg/Catch2) (2.13.8)
66+
- C++ Wrappers
67+
- [Args](https://github.com/Taywee/args) (6.2.2)
68+
- [fmt](https://github.com/fmtlib/fmt) (8.0.0)
69+
- [optional-lite](https://github.com/martinmoene/optional-lite) (3.1.1)
70+
- [string-view-lite](https://github.com/martinmoene/string-view-lite) (1.1.0)
71+
- [variant-lite](https://github.com/martinmoene/variant-lite) (1.1.0)
5872

5973

6074

6175
## How to build
6276

6377
### Windows
6478

65-
System requirements: [Visual C++ Redistributable 2015](https://www.microsoft.com/en-us/download/details.aspx?id=52685), [Visual Studio](https://visualstudio.microsoft.com/vs/).
79+
System requirements (for the libressl): [Visual C++ Redistributable 2015](https://www.microsoft.com/en-us/download/details.aspx?id=52685), [Visual Studio](https://visualstudio.microsoft.com/vs/).
6680

81+
Prerequisites: `git`, `cmake`, `ninja` or `make`, `clang` (mingw or VS) or `gcc` (mingw) or `visual studio`
6782

68-
*Coming soon*
83+
```console
84+
git clone https://github.com/dxFeed/dxfeed-c-api.git
85+
cd dxfeed-c-api
86+
mkdir build
87+
cd build
88+
cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_TLS=ON -DTARGET_PLATFORM=x64 ..
89+
cmake --build . --config Release
90+
```
6991

7092
---
7193

7294
### Linux
73-
*Coming soon*
95+
96+
Prerequisites: `git`, `cmake`, `ninja` or `make`, `clang` or `gcc`
97+
98+
```console
99+
git clone https://github.com/dxFeed/dxfeed-c-api.git
100+
cd dxfeed-c-api
101+
mkdir build
102+
cd build
103+
cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_TLS=ON -DTARGET_PLATFORM=x64 ..
104+
cmake --build . --config Release
105+
```
74106

75107
---
76108

77109

78110
### macOS
79111

80-
*Coming soon*
112+
Prerequisites: `git`, `cmake`, `ninja` or `make`, `clang`
113+
114+
```console
115+
git clone https://github.com/dxFeed/dxfeed-c-api.git
116+
cd dxfeed-c-api
117+
mkdir build
118+
cd build
119+
cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_TLS=ON -DTARGET_PLATFORM=x64 ..
120+
cmake --build . --config Release
121+
```
122+
---
123+
124+
### Android Termux
125+
126+
Prerequisites: `git`, `cmake`, `ninja`, `clang`
127+
128+
```console
129+
git clone https://github.com/dxFeed/dxfeed-c-api.git
130+
cd dxfeed-c-api
131+
mkdir build
132+
cd build
133+
cmake -DCMAKE_BUILD_TYPE=Release -DDISABLE_TLS=ON -DTARGET_PLATFORM=x64 ..
134+
cmake --build . --config Release
135+
```
81136

82137

83138
## Key features
@@ -186,8 +241,8 @@ Order source in most cases identifies source of **`Order`** and **`SpreadOrder`*
186241
* BZX - Cboe BZX
187242
* BXTR - Cboe EU SI (Systematic Internaliser)
188243
* BI20 - BIST Top20 Orders (Level2+)
189-
* CHIX - Cboe EU CXE (Chi-X)
190-
* CEUX - Cboe EU DXE
244+
* CHIX - Cboe EU CXE (Chi-X)
245+
* CEUX - Cboe EU DXE
191246
* CFE - Cboe CFE
192247
* C2OX - Cboe C2
193248
* DEA - Cboe EDGA
@@ -197,13 +252,13 @@ Order source in most cases identifies source of **`Order`** and **`SpreadOrder`*
197252
* FAIR - FairX
198253
* GLBX - Globex
199254
* ICE - ICE Futures US/EU
200-
* IST - Borsa Istanbul
201-
* MEMX - Members Exchange
255+
* IST - Borsa Istanbul
256+
* MEMX - Members Exchange
202257
* NTV - Nasdaq TotalView
203258
* NFX - Nasdaq NFX
204-
* SMFE - SmallEx
205-
* XNFI - Nasdaq NFI
206-
* XEUR - Eurex
259+
* SMFE - SmallEx
260+
* XNFI - Nasdaq NFI
261+
* XEUR - Eurex
207262
---
208263
*Price level book*:
209264

ReleaseNotes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Version 8.7.0
2+
* [DXFC-334] Fixed a bug with precision error when converting WideDecimal to Double
3+
14
Version 8.6.3
25
* [DXFC-331] Fixed a bug when deleting a PriceLevelBook object caused crashes.
36

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ set(HEADER_FILES
111111
TimeMarkUtil.hpp
112112
Version.h
113113
WideDecimal.h
114+
WideDecimal.hpp
114115
)
115116

116117
set(PARSER_HEADERS

src/Decimal.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "Decimal.h"
2121
#include "PrimitiveTypes.h"
22+
#include "WideDecimal.h"
2223

2324
#include <math.h>
2425
#include <float.h>
@@ -88,20 +89,20 @@ static const dxf_int_t EXTRA_PRECISION_DIVISORS[] = {
8889

8990
int dx_decimal_int_to_double(dxf_int_t integer, OUT dxf_double_t* decimal) {
9091
dxf_int_t power = integer & 0x0F;
91-
dxf_int_t mantissa ;
92+
dxf_int_t mantissa = dx_right_shift_int(integer, STANDARD_MANTISSA_SHIFT);
9293

9394
if (power == 0) {
9495
// extra precision and special cases
95-
dxf_int_t divisor = EXTRA_PRECISION_DIVISORS[((integer >> STANDARD_MANTISSA_SHIFT) & 0x07)];
96+
dxf_int_t divisor = EXTRA_PRECISION_DIVISORS[mantissa & 0x07];
9697

9798
if (divisor != 0) {
9899
// mantissa in highest 25 bits for supported extra precision formats
99-
*decimal = (dxf_double_t)(integer >> EXTRA_PRECISION_MANTISSA_SHIFT) / divisor;
100+
*decimal = (dxf_double_t)(dx_right_shift_int(integer, EXTRA_PRECISION_MANTISSA_SHIFT)) / divisor;
101+
100102
return true;
101103
}
102104
}
103105

104-
mantissa = (integer >> STANDARD_MANTISSA_SHIFT);
105106
*decimal = power <= UNITY_POWER ? mantissa * MULTIPLIERS[power] : mantissa / DIVISORS[power];
106107

107108
return true;

0 commit comments

Comments
 (0)