What are the differences between the following operators:-
- div and quot ?
- mod and rem ?
-
- VIP Member
- Posts: 147
- Joined: 5 Dec 2012 7:29
Div, mod, quot and rem differences
Mutall Data Management Technical Support
- Thomas Linder Puls
- VIP Member
- Posts: 1401
- Joined: 28 Feb 2000 0:01
The difference is in handling of negative numbers. See: Integral division.
Regards Thomas Linder Puls
PDC
PDC
-
- VIP Member
- Posts: 147
- Joined: 5 Dec 2012 7:29
- Thomas Linder Puls
- VIP Member
- Posts: 1401
- Joined: 28 Feb 2000 0:01
Yes, for positive numbers there is no difference.
div has the mathematical sensible property:
I.e. the result becomes one less if you subtract the divisor from the dividend.
quot does not preserve this property: the point where the result should go from 0 to -1 it will stay once more at 0. I am not really sure when you want this behavior.
We have introduced quot/rem to maintain access to the behavior div/mod used to have.
div has the mathematical sensible property:
Code: Select all
B div C = (B-C) div C - 1
quot does not preserve this property: the point where the result should go from 0 to -1 it will stay once more at 0. I am not really sure when you want this behavior.
We have introduced quot/rem to maintain access to the behavior div/mod used to have.
Regards Thomas Linder Puls
PDC
PDC
- Ferenc Nagy
- VIP Member
- Posts: 215
- Joined: 24 Apr 2007 12:26
Modulus with never negative result
Code: Select all
predicates
% 2015.07.07. Modulus with real arguments and results>=0.
realModU:(real Divided, ureal Divisor) -> ureal Modulus.
realModR:(real Divided, real Divisor) -> ureal Modulus.
clauses
% 2015.07.07. Modulus with real arguments and results>=0.
realModU(Divided,Divisor) = Divided-Divisor*floorToReal(Divided/Divisor).
realModR(Divided,Divisor) = Divided-abs(Divisor)*floorToReal(Divided/abs(Divisor)).
TIA, Regards,
Frank Nagy
Frank Nagy
- Ferenc Nagy
- VIP Member
- Posts: 215
- Joined: 24 Apr 2007 12:26
Forcing real arguments of periodical functions in a beloved range
Corrected version
The essence of the correction is the
insertion.
Example usage
Code: Select all
predicates
% 2015.07.07. Modulus with real arguments and results>=0.
realModP:(real Divided, positive Divisor) -> ureal Modulus. % 2015.07.19.
realModU:(real Divided, ureal Divisor) -> ureal Modulus.
realModR:(real Divided, real Divisor) -> ureal Modulus.
clauses
% 2015.07.19. Modulus with real arguments and results>=0.
realModP(Divided,Divisor) = Divisor*CorrectedFraction :-
Fraction=fraction(Divided/Divisor),
if Fraction<0 then
CorrectedFraction=1+Fraction %<=== ESSENCE OF CORRECTION
else
CorrectedFraction=Fraction
end if.
realModU(Divided,Divisor) = Divisor*CorrectedFraction :-
Fraction=fraction(Divided/Divisor),
if Fraction<0 then
CorrectedFraction=1+Fraction
else
CorrectedFraction=Fraction
end if.
realModR(Divided,Divisor) = realModU(Divided,abs(Divisor)).
Code: Select all
if Fraction<0 then
CorrectedFraction=1+Fraction
else
CorrectedFraction=Fraction
end if.
Example usage
Code: Select all
Code: Select all
TIA, Regards,
Frank Nagy
Frank Nagy