-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed as not planned
Labels
Description
We use annotations=true
to output nodes
in route response, then we found the output nodes
may invalid sometimes.
After investigate, it's caused by the JSON util only has one number type Number
, which defined as double
:
osrm-backend/include/util/json_container.hpp
Lines 89 to 94 in 15f0ca8
struct Number | |
{ | |
Number() = default; | |
Number(double value_) : value{value_} {} | |
double value; | |
}; |
It means whatever the internal number type is, it will be converted to
double
before output. For some long std::uint64_t
, the value will be cut in this conversion.
In our test, the nodeID 9280805980001101
will be cut to 9280805980001100
, which results invalid nodeID.
Here's some test code:
// Example program
#include <iostream>
#include <string>
#include <cstdint>
#include <iomanip>
int main()
{
std::uint64_t id = 9280805980001101;
double d_id = static_cast<double>(id);
std::uint64_t convert_back_id = static_cast<std::uint64_t>(d_id);
std::cout << id << std::endl;
std::cout << std::fixed << std::setprecision(6) << d_id << std::endl;
std::cout << convert_back_id << std::endl;
}
// output:
9280805980001101
9280805980001100.000000
9280805980001100
Full story please refer to Telenav#276
Any suggestion? Is it possible to have more Number types in the JSON util?
Many thanks in advance!