From: bukinm AT inp DOT nsk DOT su (Michael Bukin) Newsgroups: comp.os.msdos.djgpp Subject: Re: SIGFPE HELP!!! Date: 31 Mar 1997 02:38:18 GMT Organization: BINP SD RAS Lines: 46 Message-ID: <5hn82q$huh@sky.inp.nsk.su> References: <01bc3d54$db2c6c00$ad971fc3 AT stefabiz DOT vol DOT it> Reply-To: bukinm AT inp DOT nsk DOT su NNTP-Posting-Host: h-bukin.inp.nsk.su To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp >I have a problem using this little function : >unsigned int Maschera[30]; >void Crea_Mask ( BITMAP *p ) >{ > int a, b; > for (a = 0; a < p->h; a++) > { > Maschera[a] = 0; > for (b = 0; b < p->w; b++) > if (p->line[a][b] != 0) > Maschera[a] = Maschera[a] | (int) pow ((int) 2, (int) (p->w - b)); > } >} >into a program. After a while it return a SIGFPE error (I really do not >understand why. I used UINT and *not* float). 1. Pow accepts two double arguments and returns double. In normal case compiler will make implicit type casting from int to double. But if you did not declare pow (e.g. by including math.h), compiler will not know of arguments types and will produce incorrect result. Use -Wall switch to see if it is the case. 2. Maybe p->h is larger than 30? P.S. For getting power of two it is better to use either table lookup: unsigned int power_of_two[32] = { 1, 2, 4, 8, ... }; .. Maschera[a] |= power_of_two[p->w - b]; /* p->w must be less than 32. */ or bit shifts: int a, b; unsigned int bit_mask; for (...) { /* p->w must be less than 32. */ for (b = 0, bit_mask = power_of_two[p->w]; b < p->w; b++, bit_mask <<= 1) if (...) Maschera[a] |= bit_mask; } >As you can understand, the function take a sprite and create the mask for a >pixel collision detection. >Thank you!