lua-users home
lua-l archive

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


Doug Currie wrote:
[...]
> Searching the MS site, I found
> 
>     Conversions from *float*, *double*, or *long double* values to
>     *unsigned long* are not accurate if the value being converted is
>     larger than the maximum positive *long* value.  

This whole field is riddled with dragons; watch where you step. I
recently had to deal with some (third party, commercial) code that was
doing:

float delta = [positive or negative number];
unsigned int x = x + (unsigned int) delta;

I was finding that on one platform (Intel) the sprites moved in both
directions. On another platform (ARM) the sprites would only move to the
right. Turns out that on ARM, casting a negative float to an unsigned
int produces 0, which on Intel it's equivalent to casting it to a signed
int.

And they're *both* right --- you're allowed either interpretation. (The
game had been written for Intel, and was wrong.)

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ ⍎'⎕',∊N⍴⊂S←'←⎕←(3=T)⋎M⋏2=T←⊃+/(V⌽"⊂M),(V⊝"M),(V,⌽V)⌽"(V,V←1⎺1)⊝"⊂M)'
│ --- Conway's Game Of Life, in one line of APL

Attachment: signature.asc
Description: OpenPGP digital signature