lua-users home
lua-l archive

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


> Hello.  Getting a compilation error on MSVC 6.0 SP6 on Windows XP with the
> latest Lua.  The error is as follows:
> 
> Line 338 of lmathlib.c:
> static lua_Number I2d (Rand64 x) {
>   return (lua_Number)(trim64(x) >> shift64_FIG) * scaleFIG;
> }
> 
> gives this error:
> compile error C2520: conversion from unsigned __int64 to double not
> implemented, use signed __int64

Thanks for the report.


> Of course, these are both specific fixes _for my case_ and I do not know
> enough about Lua to make these either conditional nor portable.  I am happy
> to test any fixes on my system though, if anyone wants to make this old
> compiler officially work again!

I guess this does the trick:

static lua_Number I2d (Rand64 x) {
  SRand64 sx = (SRand64)(trim64(x) >> shift64_FIG);
  lua_Number res = (lua_Number)(sx) * scaleFIG;
#if FIGS == 64
  if (sx < 0) res += 1.0;  /* correct the two's complement if negative */
#endif
  /* if FIGS is smaller, the shift makes sure 'sx' is non negative */
  lua_assert(0 <= res && res < 1);
  return res;
}


('SRand64' is the signed equivalent of 'Rand64'.)

-- Roberto