How to multiply a 64 bit integer by a fraction in C++ while minimizing error? [duplicate]
问题 This question already has answers here : Most accurate way to do a combined multiply-and-divide operation in 64-bit? (10 answers) Closed 5 years ago . Given a 64 bit (signed) long long or __int64 , how would you go about multiplying it by an arbitrary fraction while at the same time minimizing error? Three simple sketches: int64_t numerator = ...; int64_t denominator = ...; int64_t x = ...; // a, lossy double conversion for large values double fraction = static_cast<double>(numerator) /