[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: PCB nanometer git tree
Andrew Poelstra:
> On Thu, Aug 11, 2011 at 09:30:34PM +0200, Karl Hammar wrote:
...
> > -#define LARGE_VALUE (LONG_MAX / 2 - 1) /* maximum extent of board and elements */
> > +#define LARGE_VALUE LONG_MAX /* (LONG_MAX / 2 - 1) maximum extent of board and elements */
...
> > Why do you want to use only half the range?
>
> So that the width of a "max width" box can be calculated as
> LARGE_VALUE - (-LARGE_VALUE) without overflow,
Hmm, wouldn't it be better to use unsigned here?
For
typedef unsigned long Coord;
Coord width( Coord a, Coord b ) {
if (a > b) {
return a - b;
} else {
return b - a;
}
}
do work without overflow for all possible walues of a and b.
And we don't really need a signed type, do we?
> and so that two maximum widths can be averaged as (x + x) / 2.
Isn't that most easily fixed by using a wider type during addition?
Coord mean( a, b) {
bigger_int c = ((bigger_int) a + (bigger_int) b);
return (Coord) c;
}
Also, most (all?) arch. have a carry bit, which means you could
possible have a n+1 wide type during adding and div by 2. Maybe that
would involve to much hackery.
Well, not any great consern, just thinking aloud.
Regards,
/Karl Hammar
-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user