diff --git a/src/Data/EuclideanRing.erl b/src/Data/EuclideanRing.erl index 48078387..c215568a 100644 --- a/src/Data/EuclideanRing.erl +++ b/src/Data/EuclideanRing.erl @@ -1,20 +1,11 @@ -module(data_euclideanRing@foreign). -export([intDegree/1, intDiv/2, intMod/2, numDiv/2]). -intDegree(X) -> abs(X). +intDegree(X) -> erlang:abs(X). intDiv(_, 0) -> 0; -intDiv(X, Y) when Y > 0 -> floor_(X / Y); -intDiv(X, Y) -> -floor_(X / -Y). - -% Not supported natively until erlang 20 -floor_(X) -> - T = erlang:trunc(X), - case (X - T) of - Neg when Neg < 0 -> T - 1; - Pos when Pos > 0 -> T; - _ -> T - end. +intDiv(X, Y) when X < 0 -> (X - erlang:abs(Y) + 1) div (Y); +intDiv(X, Y) -> X div Y. intMod(_, 0) -> 0; intMod(X, Y) ->