Re: [AD] compare ALLEGRO_COLOR with memcmp |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2011-06-06, at 6:02 PM, Jon Rafkind wrote:
> I noticed there are two places in 5.1 that are comparing ALLEGRO_COLOR
> using memcmp
>
> $ grep -n memcmp *
> bitmap.c:553: if (memcmp(&pixel, &mask_color,
> sizeof(ALLEGRO_COLOR)) == 0) {
> optimized.c:196: !memcmp(bc, &white, sizeof(ALLEGRO_COLOR))) {
>
> Since ALLEGRO_COLOR's use floats internally is this dangerous? In my own
> code I compare the values to some epsilon value
>
> if (fabs(c1.r - c2.r) < 0.0001 &&
> ...blue, green, alpha)
It depends what your purposes are. The ones in Allegro are safe, because any
2 colors created on the same system with al_map* will have the same bit patterns.
If you're creating them on different systems, they _should_ be the same for most
systems but will not be the same for _all_ systems.
Trent