I have an issue on where my double value lose precision when copied. Here is two stucts and a std::map where the value are stored:
struct orderlist{
double price = 0;
double quantity = 0;
double id = 0;
int pairID = 0;
int order_type;
};
struct bookOrder{
double price = 0;
double quantity = 0;
};
std::map<double, bookOrder>* put_orders;
std::map<double, bookOrder>* ask_orders;
Then here is the code to extract the best prices :
double orderbook::getLowestAsk(){
bookOrder ord;
std::lock_guard lock(m_mutex);
ord = ask_orders->rbegin()->second;
return ord.price;
}
double orderbook::getHighestBid(){
bookOrder ord;
std::lock_guard lock(m_mutex);
ord = put_orders->begin()->second; // put_orders first entry struct contain price of 54.87
return ord.price; // ord.price is 54.869999999999997
}
For example, if the price stored into a stuct in the map is 54.87 (I clearly see that proper number in the debugger) then on the "ord = put_orders->begin()->second;", it assign the value 54.869999999999997 to price. I did not do any conversion, it's double everywhere.