Operator MOD
#27
(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".
Reply


Messages In This Thread
Operator MOD - by Chris - 11-27-2022, 07:09 PM
RE: Operator MOD - by Pete - 11-27-2022, 07:35 PM
RE: Operator MOD - by Chris - 11-27-2022, 07:47 PM
RE: Operator MOD - by SMcNeill - 11-27-2022, 08:03 PM
RE: Operator MOD - by Chris - 11-27-2022, 08:17 PM
RE: Operator MOD - by Pete - 11-27-2022, 08:23 PM
RE: Operator MOD - by Chris - 11-27-2022, 08:30 PM
RE: Operator MOD - by SMcNeill - 11-27-2022, 08:44 PM
RE: Operator MOD - by mnrvovrfc - 11-27-2022, 08:32 PM
RE: Operator MOD - by bplus - 11-27-2022, 08:42 PM
RE: Operator MOD - by Chris - 11-27-2022, 08:54 PM
RE: Operator MOD - by SMcNeill - 11-27-2022, 08:57 PM
RE: Operator MOD - by SMcNeill - 11-27-2022, 09:02 PM
RE: Operator MOD - by Jack - 11-27-2022, 09:02 PM
RE: Operator MOD - by Chris - 11-27-2022, 09:02 PM
RE: Operator MOD - by SMcNeill - 11-27-2022, 09:06 PM
RE: Operator MOD - by Chris - 11-27-2022, 09:08 PM
RE: Operator MOD - by Chris - 11-27-2022, 09:14 PM
RE: Operator MOD - by Jack - 11-27-2022, 09:18 PM
RE: Operator MOD - by Pete - 11-27-2022, 09:23 PM
RE: Operator MOD - by Chris - 11-27-2022, 09:28 PM
RE: Operator MOD - by Chris - 11-27-2022, 09:52 PM
RE: Operator MOD - by Pete - 11-27-2022, 10:41 PM
RE: Operator MOD - by mnrvovrfc - 11-28-2022, 01:17 AM
RE: Operator MOD - by mnrvovrfc - 11-28-2022, 04:01 AM
RE: Operator MOD - by mnrvovrfc - 11-28-2022, 02:57 AM
RE: Operator MOD - by Pete - 11-28-2022, 03:21 AM
RE: Operator MOD - by Jack - 11-28-2022, 10:13 AM
RE: Operator MOD - by Kernelpanic - 11-28-2022, 04:03 PM
RE: Operator MOD - by Jack - 11-28-2022, 11:56 AM
RE: Operator MOD - by Chris - 11-28-2022, 03:21 PM
RE: Operator MOD - by Chris - 11-28-2022, 04:06 PM
RE: Operator MOD - by Pete - 11-28-2022, 07:02 PM
RE: Operator MOD - by mnrvovrfc - 11-28-2022, 08:23 PM
RE: Operator MOD - by SMcNeill - 11-28-2022, 09:54 PM
RE: Operator MOD - by mnrvovrfc - 11-28-2022, 10:10 PM
RE: Operator MOD - by Pete - 11-28-2022, 10:23 PM
RE: Operator MOD - by Kernelpanic - 11-29-2022, 11:12 PM
RE: Operator MOD - by SMcNeill - 11-28-2022, 10:33 PM
RE: Operator MOD - by Kernelpanic - 11-28-2022, 11:46 PM
RE: Operator MOD - by mnrvovrfc - 11-29-2022, 12:10 AM
RE: Operator MOD - by Pete - 11-29-2022, 12:00 AM
RE: Operator MOD - by Kernelpanic - 11-29-2022, 12:05 AM
RE: Operator MOD - by SMcNeill - 11-29-2022, 12:35 AM
RE: Operator MOD - by Kernelpanic - 11-29-2022, 12:25 AM
RE: Operator MOD - by Pete - 11-29-2022, 12:36 AM
RE: Operator MOD - by bplus - 11-29-2022, 01:29 AM
RE: Operator MOD - by Pete - 11-29-2022, 01:42 AM
RE: Operator MOD - by bplus - 11-29-2022, 04:41 AM
RE: Operator MOD - by SMcNeill - 11-29-2022, 06:24 AM
RE: Operator MOD - by SMcNeill - 11-29-2022, 06:34 AM
RE: Operator MOD - by bplus - 11-29-2022, 12:27 PM
RE: Operator MOD - by Pete - 11-29-2022, 11:58 PM
RE: Operator MOD - by Kernelpanic - 11-30-2022, 02:50 AM
RE: Operator MOD - by SMcNeill - 11-30-2022, 03:49 AM
RE: Operator MOD - by Kernelpanic - 12-01-2022, 12:41 AM
RE: Operator MOD - by vince - 11-30-2022, 12:41 PM
RE: Operator MOD - by Chris - 12-03-2022, 08:19 AM
RE: Operator MOD - by SMcNeill - 12-03-2022, 08:31 AM
RE: Operator MOD - by Pete - 12-03-2022, 09:06 AM
RE: Operator MOD - by mnrvovrfc - 12-03-2022, 11:56 AM
RE: Operator MOD - by SMcNeill - 12-03-2022, 12:08 PM
RE: Operator MOD - by Kernelpanic - 12-03-2022, 05:07 PM
RE: Operator MOD - by Pete - 12-03-2022, 05:12 PM
RE: Operator MOD - by Kernelpanic - 12-03-2022, 05:20 PM
RE: Operator MOD - by SMcNeill - 12-03-2022, 12:30 PM
RE: Operator MOD - by mnrvovrfc - 12-03-2022, 12:31 PM
RE: Operator MOD - by Pete - 12-03-2022, 03:31 PM
RE: Operator MOD - by DSMan195276 - 12-03-2022, 05:57 PM
RE: Operator MOD - by Kernelpanic - 12-03-2022, 06:48 PM
RE: Operator MOD - by Pete - 12-03-2022, 06:05 PM



Users browsing this thread: 34 Guest(s)