delphi - Comparison of negative and positive numbers -
i have comparison function getting way complex i'm trying do. receive double can positive or negative. storing global variable needs smallest value. in terms of comparison, means smallest positive number, or if incoming values negative, smallest global value negative.
my code turning bunch of if
statements handling if incoming positive or negative. need compare differently if current global value positive or negative.
is there better way compare 2 numbers , lowest of two?
partial example code:
if nestobject.rectangularscrap <> 0 begin if nestobject.rectangularscrap > 0 begin //positive rect scrap if(nestobject.rectangularscrap < gbestrect) begin gbestrect := nestobject.rectangularscrap; end; if(nestobject.rectangularscrap > gworstrect) begin gworstrect := nestobject.rectangularscrap; end; end else begin //negative rect scrap if gbestrect > 0 begin //global value positive gbestrect := nestobject.rectangularscrap; end else begin //global value negative, change both values postive compare if((-1*nestobject.rectangularscrap) < (-1*gbestrect)) begin gbestrect := nestobject.rectangularscrap; end; if((-1*nestobject.rectangularscrap) > gworstrect) begin gworstrect := nestobject.rectangularscrap; end; end; end; end;
have tried min function ?
Comments
Post a Comment