![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
Decimal literal -> T, without a detour through double when T is exact. More...
#include <cctype>#include <cstdlib>#include <string>#include "line/num/number.h"#include "line/util/error.h"Go to the source code of this file.
Namespaces | |
| namespace | line |
Functions | |
| Rational | line::rational_from_decimal (const std::string &s) |
| The literal as an exact rational, num/10^k with no rounding. | |
| template<class T> | |
| T | line::num_from_decimal (const std::string &s) |
| Parse a decimal literal into T. | |
| template<> | |
| Rational | line::num_from_decimal< Rational > (const std::string &s) |
| double | line::dbl_from_decimal (const std::string &s, double fallback) |
| Parse a decimal literal as a plain double (multiplicities, populations, tolerances). | |
Decimal literal -> T, without a detour through double when T is exact.
This is the boundary at which a model file becomes numbers, and it is the one place where "exact arithmetic" has to decide what it is exact ABOUT. A host demand written 0.01 in an .lqnx file denotes the rational 1/100. The double nearest to it is 0.01000000000000000020816681711721685...; routing that literal through num_traits<Rational>::from_double would make the exact backend compute, with no rounding at all, the answer to a model that is not the one on disk. So the exact backend parses the decimal digits directly into num/10^k, and the inexact backends keep strtod, which is what MATLAB's str2double and Java's Double.parseDouble also do.
The consequence to keep in mind when comparing the two runs: they are not two evaluations of one arithmetic problem, they are the exact solution of the declared model versus the floating-point solution of its double rounding. Their difference is bounded below by the input rounding, of order 1e-17 relative here, and any larger gap is accumulated error in the solver.
Definition in file decimal.h.