lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 15.04.2014 23:48, schrieb Peter Cawley:
... only VS2010 x86 exhibits the wrong behaviour. ...
Yes, but (no matter whatever it may be worth):

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <math.h>

int _tmain(int argc, _TCHAR* argv[])
{
  unsigned __int64 x = 0xFFFFFFFFFFFFFFFFL;
  for (long exp = 1; exp < 20; exp++) {
      unsigned __int64 dec = (unsigned __int64)pow(10.0,exp);
      double d = (double)x/dec;
      unsigned __int64 y = ((unsigned __int64)d)*(dec-1);
      printf("10^%02i: %I64x %I64x %g\n", exp, x, y, d/dec*(dec-1));
  }
  return 0;
}

results in:

10^01: ffffffffffffffff e666666666666a00 1.66021e+018
10^02: ffffffffffffffff fd70a3d70a3d7220 1.82623e+017
10^03: ffffffffffffffff ffbe76c8b4395990 1.84283e+016
10^04: ffffffffffffffff fff972474538e8e5 1.84449e+015
10^05: ffffffffffffffff ffff583a53b81b19 1.84466e+014
10^06: ffffffffffffffff ffffef390856df53 1.84467e+013
10^07: ffffffffffffffff fffffe5280449536 1.84467e+012
10^08: ffffffffffffffff ffffffd50c507c9f 1.84467e+011
10^09: ffffffffffffffff fffffffb8a321ff7 1.84467e+010
10^10: ffffffffffffffff fffffffeb4f13c99 1.84467e+009
10^11: ffffffffffffffff ffffffeecb92c010 1.84467e+008
10^12: ffffffffffffffff ffffffeed5780668 1.84467e+007
10^13: ffffffffffffffff fffffc4b83e11a3e 1.84467e+006
10^14: ffffffffffffffff ffffd7ea4a2fef6d 184467
10^15: ffffffffffffffff fffd5b44d6dab7f2 18446.7
10^16: ffffffffffffffff ffe80a4cfa33f8cc 1844.67
10^17: ffffffffffffffff ff59ee833b2fff48 184.467
10^18: ffffffffffffffff f9ccd8a1c507ffee 18.4467
10^19: ffffffffffffffff fffffffffffffffe 2

Cheers
Frank