CGAL:将商转换为双精度

CGAL: convert quotient to double

我在转换 CGAL QP 求解器时遇到问题

typedef CGAL::Gmpzf ET;
...define a quadratic program qp here...
Solution s = CGAL::solve_quadratic_program(qp, ET());
assert (s.solves_quadratic_program(qp));
cout<<"QP objective = "<<s.objective_value()<<endl;
// The above returns a value of type CGAL::Quotient<ET>
// and I need to convert it to double
double n = s.objective_value_numerator().to_double();
double d = s.objective_value_denominator().to_double();
cout<<"QP objective 2 = "<<n/d<<endl;

我得到了:

QP objective = -2.57497e-22/2.01459e-22 
QP objective 2 = -nan

我检查并观察到 ​​n = -infd = inf

我们如何正确地将商数转换为双精度数?

提前感谢您的任何建议!!

CGAL 有一个函数 CGAL::to_double that can be used on most number types and in particular on Quotient. It has special code 正是针对这种分子和分母会溢出的情况。它 not 有下溢代码,这不会发生在整数的商上,但可能会发生在 Gmpzf 上,产生 0/0.