CubicDesign wrote:
> I need a fast function that compares three numbers and returns the
> biggest.
> Do you know an ASM library that can do such a calculation?
>
> I downloaded a library called 'Math387' which implements such a function
> but for two numbers, not for three.

The name of that unit suggests it's a unit written for the Intel 80387
math coprocessor; is it really that old?

> The person who made the library pretends that it is made in ASM but
> actually, it has the same speed as Borland's Max function.

Being written in assembler and performing the same as the function in the
Math unit aren't mutually exclusive things.

> I need this function in a loop that is executed 100,000,000 times. By
> itself, it takes 2.1 seconds.

For one hundred million things, that seems pretty fast already. How fast
do you want it go instead?

> *Borland Max function:*
>
> function Max(const A, B: Integer): Integer;
> begin
>   if A > B then
>     Result := A
>   else
>     Result := B;
> end;

Yep. There's not really much more you can do with that.

> *My function (for 3 numbers):*
>
> function Find_Max(const v1,v2,v3: integer): Integer;
> begin
>  Result:= v1;
>  if (v2 >  Result) then  Result:= v2;
>  if (v3 >  Result) then  Result:= v3;
> end;

That executes two comparisons and a maximum of three assignments.

function Max(const A, B, C: Integer): Integer;
begin
  if A > B then
    if A > C then
      Result := A
    else
      Result := C
  else
    if B > C then
      Result := B
    else
      Result := C;
end;

That executes two comparisons and a maximum of one assignment.

-- 
Rob


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to