Results 1 to 7 of 7

Thread: [Request] Mod Funcion between two extended values?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    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...
    Last edited by User137; 09-07-2011 at 11:22 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •