11-28-2022, 04:01 AM
(11-28-2022, 01:17 AM)mnrvovrfc Wrote: ... "MOD" is as sacred as plus, minus and whatever else is an operator and therefore it shouldn't be written as function call. Sadly, to be able to do that, QB64(PE) would have to support OOP and the programmer would have to override "MOD" operator, like actually has to be done in C++.
Look what has to be done in Freebasic only to get a "-9 MOD 5" which returns 1 instead of -4:
Code: (Select All)
Type ANUM
As Integer n
End Type
operator Mod ( byref number1 as ANUM, byref number2 as ANUM ) as integer
dim templ as integer
templ = number1.n MOD number2.n
IF number1.n < 0 THEN templ = (templ + number2.n) MOD number2.n
return templ
end operator
dim i as integer, a as ANUM, d as ANUM
d.n = 5
for i = -10 to 10
a.n = i
print i; " mod"; 5, a mod d
next
An UDT is terminally needed so the programmer could still use the ordinary "MOD".