-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathprecision_debug.cpp
More file actions
42 lines (33 loc) · 1.74 KB
/
precision_debug.cpp
File metadata and controls
42 lines (33 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <iomanip>
#include "qaultra/data/unified_datatype.hpp"
using namespace qaultra::data;
int main() {
// Test the exact same values as in the test
Date trading_date(2024, 1, 15);
// Show what happens when double 10.2 becomes float then double
double original_close = 10.2;
float float_close = static_cast<float>(original_close);
double recovered_close = static_cast<double>(float_close);
std::cout << std::fixed << std::setprecision(15) << std::endl;
std::cout << "Original double: " << original_close << std::endl;
std::cout << "As float: " << float_close << std::endl;
std::cout << "Back to double: " << recovered_close << std::endl;
std::cout << "Difference: " << (recovered_close - original_close) << std::endl;
// Create the StockCnDay exactly as in test
StockCnDay stock_day(trading_date, "000001.XSHE", 1000, 11.5, 9.5, 10.0, 10.5, 9.8, 10.2, 1000000, 10200000);
std::cout << "\nStockCnDay results:" << std::endl;
std::cout << "get_close(): " << stock_day.get_close() << std::endl;
std::cout << "Expected: 10.2" << std::endl;
std::cout << "Exact diff: " << (stock_day.get_close() - 10.2) << std::endl;
std::cout << "Abs diff: " << std::abs(stock_day.get_close() - 10.2) << std::endl;
// Test with tolerance
double tolerance = 1e-9;
bool passes_tolerance = std::abs(stock_day.get_close() - 10.2) < tolerance;
std::cout << "Passes 1e-9 tolerance: " << (passes_tolerance ? "YES" : "NO") << std::endl;
// Try larger tolerance
tolerance = 1e-6;
passes_tolerance = std::abs(stock_day.get_close() - 10.2) < tolerance;
std::cout << "Passes 1e-6 tolerance: " << (passes_tolerance ? "YES" : "NO") << std::endl;
return 0;
}