I have the following code:
typedef __int64 BIG_INT;
typedef double CUT_TYPE;
#define CUT_IT(amount, percent) (amount * percent)
void main()
{
    CUT_TYPE cut_percent = 1;
    BIG_INT bintOriginal = 0x1FFFFFFFFFFFFFF;
    BIG_INT bintAfter = CUT_IT(bintOriginal, cut_percent);
}
bintAfter's value after the calculation is 144115188075855872 instead of 144115188075855871 (see the "2" in the end, instead of "1"??).
On smaller values such as 0xFFFFFFFFFFFFF I get the correct result.
How do I get it to work, on 32bit app? What do I have to take in account? My aim is to cut a certain percentage of a very big number.I use VC++ 2008, Vista.
double has a 52 bit mantissa, you're losing precision when you try to load a 60+ bit value into it.
Floating point calculations aren't guaranteed to be perfectly accurate, and you've defined CUT_TYPE as double.
See this answer for more info: Dealing with accuracy problems in floating-point numbers
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论