Clone
ixen <ixen@copyhandler.com>
committed
on 07 Mar 16
Fixed the 64bit division problem (CH-227).
LoggerImprovements + 5 more
src/libchcore/MathFunctions.cpp (+5 -7)
1 1 #include "stdafx.h"
2 2 #include "MathFunctions.h"
3 3 #include <boost/numeric/conversion/cast.hpp>
4 4
5 5 namespace chcore
6 6 {
7 7         namespace Math
8 8         {
9 9                 double Div64(unsigned long long ullNumber, unsigned long long ullDenominator)
10 10                 {
11 11                         if (ullDenominator == 0)
12 12                                 return 0.0;
13 13
14                           const unsigned long long ullMaxInt32 = (unsigned long long)std::numeric_limits<int>::max();
15                           while (ullNumber > ullMaxInt32 || ullDenominator > ullMaxInt32)
16                           {
17                                   ullNumber >>= 1;
18                                   ullDenominator >>= 1;
  14                         return (double)ullNumber / (double)ullDenominator;
19 15                 }
20 16
21                           return boost::numeric_cast<double>(ullNumber) / boost::numeric_cast<double>(ullDenominator);
  17                 LIBCHCORE_API double Div64(unsigned long long ullNumber, double dDenominator)
  18                 {
  19                         return ullNumber / dDenominator;
22 20                 }
23 21         }
24 22 }