Maybe something like this:
Code:
function ModExt(a, b: Extended): Extended;
var a_negative, b_negative: boolean;
begin
if b=0 then begin
// This would otherwise make endless loop
result:=0; exit;
end;
a_negative:=a<0;
b_negative:=b<0;
result:=abs(a);
b:=abs(b);
while result>=b do
result:=result-b;
if a_negative then
result:=-result;
if b_negative then
result:=-result;
end;
But as you can see it can be a slow function if difference in numbers is big. Try this with A 100000 and B 0.00001 and you know what i mean... Also the more time it takes the more inaccurate the result may be.
edit #6?: Oops, result-b, not result/b
Not satisfied with those negative counts still... Because of (result>b) both of them must be abs()'d. But also if both would be negative then negatives would cause positive total effect. I had 1 variable version on earlier edit but cba now... This function is close to useless anyway.
Hmm, could optimize with division me thinks...
Bookmarks