Modulo (divisor) function as found in a lot of programming languages: Python (%), Ruby (%), Matlab (mod), Fortran (modulo), Common Lisp (mod) and so on.. This is not the same as the remainder operator found in Pascal (mod), C (%), Java (%) and PHP (%).. and so on. Tho note that positive numbers will be the same, so: (Modulo(10,7) = 10 mod 7) but (Modulo(-10,7) <> -10 mod 7)... or (Modulo(10,-7) <> 10 mod -7).. The first one returns -4, and the second one returns 3.
You will notice that a the mod operator in pascal retains the sign of X, while modulus (function i posted) retains the sign of Y. Zero (0) on the right side will result in Division by zero exception.
pascal Code:
function Modulo(X, Y: Double): Double; overload;
begin
Result := X - Floor(X / Y) * Y;
end;
function Modulo(X, Y: Double): Integer; overload;
begin
Result := X - Floor(X / Y) * Y;
end;
A property of this is that it can generally replace functions like FixD, FixRad (and similar).
EG:
pascal Code:
begin
WriteLn(Modulo(364.5, 360)); //FixDeg (always in range of 0 to 360)
WriteLn(Modulo(-60, 360));
WriteLn(Modulo(1.0,-360)); //Always in range of 0 to -360.
WriteLn(Modulo(-361.0,-360));
WriteLn(Modulo(6.5340, PI+PI)); //FixRad
WriteLn(Modulo(-1.1977, PI+PI));
end.