lua-users home
lua-l archive

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


PMFJI, but this is slightly too weird for me to not comment upon...

Quoth hleuwer <herbert.leuwer@t-online.de>, on 2010-02-17 00:36:16 +0100:
> -      hi = (u_long) floor(val / (double)(2 ^ ul_bits));
> -      lo = (u_long) (val - hi * (double)(2 ^ ul_bits));

... does that really mean someone mistook ^ for exponentiation in C?

> +      hi = floor(val / pow(2.0, ul_bits));
> +      lo = val - hi * pow(2, ul_bits);

I wouldn't.  ldexp exists from C89 and can do this by changing the
exponent part of the double (assuming binary floating point) rather
than doing a full numeric exponentiation:

  val / pow(2.0, ul_bits) ==> ldexp(val, -ul_bits)
  hi * pow(2.0, ul_bist) ==> ldexp(val, ul_bits)

where the second arguments are ints.

   ---> Drake Wilson