Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Operator MOD
#31
(11-28-2022, 10:13 AM)Jack Wrote: @Chris
Mathematica gives the following answers
Mod[-1, 5] -> 4
Mod[-1.4, 5] -> 3.6
Mod[1.4, 5] -> 1.4
Mod[-7, 5] -> 3
Mod[-7.1, 5] -> 2.9
. . .

Interesting! I've now installed (GNU)Octave and it gives the same results as the expensive Mathematica.

I think I figured out where MOD is used in calculating the calendar. Let's see if my belief is correct.  Rolleyes

[Image: Octave-MOD2022-11-28.jpg]
Reply
#32
Maybe I will add something else from myself.
The MOD is derived from the GW Basic of the 1980s.
QB64 operators are not listed in the list of operators. Treated a bit neglectfully. for decades, no one wanted to modify the operator in terms of universality and correctness of the results. And what the hell, operations on integers are enough, who needs more? Someone will say that it can be replaced with a function and that's it - sure it can, but is it profitable in every situation? If I have an arithmetic sequence in which MOD is contained even three times and other operators, does it make sense to use the function in this situation? What remains is the fragmentation of the pattern has individual elements. It can be compared to writing a book. So as I suggested, you should add a new math operator or modify the old man. Pocket calculator with MOD function can calculate modulo without errors. QB64 seems to be a more serious tool and more demanding. I don't know how much work it takes to add a new math operator, but I think it's worth it. I assume that most of the forum members do not share my opinion - it's hard to survive.


Regards - Chris
Reply
#33
Mod won't be modified because QB64 is dedicated to being QuickBASIC compatible with the goal being programs will run the same, in terms of output, on both platforms.

I find the function for recognizing patterns good enough for any situation I have encountered. I just coded an even better update for integers with this single line not conditions needed update...

Code: (Select All)
$CONSOLE:ONLY
' Testing modx 5
FOR i = 20 TO -20 STEP -1
    i$ = LTRIM$(STR$(i))
    LOCATE , 4 - LEN(i$): PRINT LTRIM$(STR$(i));: LOCATE , 5: PRINT "modx j ="; modx(i, 5)
NEXT
SLEEP
' Testing modx -5
FOR i = 20 TO -20 STEP -1
    i$ = LTRIM$(STR$(i))
    LOCATE , 4 - LEN(i$): PRINT LTRIM$(STR$(i));: LOCATE , 5: PRINT "modx j ="; modx(i, -5)
NEXT

FUNCTION modx (i, j)
    modx = (ABS(i) - ABS(j) * ((ABS(i) \ ABS(j)) + (1 - SGN(i)) \ 2)) * SGN(i MOD j)
END FUNCTION

So to me this is not a pressing issue. I'd put it left down (as apposed to right up) there with making SELECT CASES, but you never know. If a current dev or someone new comes along who has a personal fascination with topic, something might get pushed to the repo.

My advice would be if you want to lobby for it, Since Steve doesn't appear interested, I'd recommend sending a PM to Matt (DSMan195276) or luke.

In conclusion, if MOD were buggy, I'm pretty certain the dev team would be all over it, but as I stated earlier the QB version of MOD works correctly as designed, and although there is absolute merit in an operator as you described, well, there are a lot of developed functions built into calculators that are not made as keywords in a computer language. That's why many of us build routines like String Math and decfloat.


Pete
Reply
#34
"QB64 must be changed because Galleon said so" or along those lines, will keep bringing people into this forum who aren't lurkers.

I guess there was a topic just like this one in the forum where he was administrator. Otherwise, but why late in 2022 instead of 1992... I don't get it. And the intent to make it look better, with floating-point dividends?

Arrow A mistake to have proposed at all a division remainder function from the C runtime library that could work with floating-point numbers. Only because a few people right now disagree with how one operator works.

Actually I think the plain old division "/" symbol sucks hard for integers and "\" shouldn't be necessary. MOD is actually in the same camp. But I'm not going to campaign for it. "The old man"? LOL find another programming language then that might bear another disappointment. We're supposed to love Fortran while fumbling with numbers in a programming language.

P.S. In the example I took from Wikipedia I was absolutely compelled to use integer division instead of ordinary "/" because with the latter, it produced incorrect whole-number quotients. This is mind-boggling to me, with integers only involved. But one more time, I'm not going to gripe about it and must accept a work-around.
Reply
#35
As I posted for Pete -- getting the pattern one wants is completely trivial.  Why is this such an issue for folks??

Code: (Select All)
For i = 10 To -10 Step -1
    Print i Mod 5, ModX(i, 5)
Next

Function ModX (num1, num2)
    ModX = ((num1 Mod num2) + num2) Mod num2
End Function


^That's it.  That's all one has to do to get the results they want.   If you have some God-fearing aversion for Functions, then just use  ((num1 Mod num2) + num2) Mod num2 directly.   It's not rocket science -- it's just remainders after division!
Reply
#36
(11-28-2022, 09:54 PM)SMcNeill Wrote: As I posted for Pete -- getting the pattern one wants is completely trivial.  Why is this such an issue for folks??
Maybe one "issue" is for the code Chris presented in his other thread so full of "MOD" and regular division...

Well, I have to make at least one attempt to create an account on Github to request a "PMOD" operator. Because it might be less effective to disturb DSMan195276 in particular...
Reply
#37
Steve, yours needs some work if you pop a negatives in there as the modulo.


Code: (Select All)
$CONSOLE:ONLY
PRINT "Equation  Steve's Results  |  Pete's Results"
PRINT
FOR i = 10 TO -10 STEP -1 ' Modulo 5
    PRINT i; "mod 5 =";: LOCATE , 18: PRINT Steve_ModX(i, 5), , Pete_modx(i, 5)
NEXT
PRINT "----------------------Negative Mods----------------------"
FOR i = 10 TO -10 STEP -1 ' Modulo -5
    PRINT i; "mod -5 =";: LOCATE , 18: PRINT Steve_ModX(i, -5), , Pete_modx(i, -5)
NEXT

FUNCTION Pete_modx (i, j)
    Pete_modx = (ABS(i) - ABS(j) * ((ABS(i) \ ABS(j)) + (1 - SGN(i)) \ 2)) * SGN(i MOD j)
END FUNCTION

FUNCTION Steve_ModX (num1, num2)
    Steve_ModX = ((num1 MOD num2) + num2) MOD num2
END FUNCTION

Pete
Shoot first and shoot people who ask questions, later.
Reply
#38
Fixed.  Tongue

Code: (Select All)
$Console:Only
Print "Equation  Steve's Results  |  Pete's Results"
Print
For i = 10 To -10 Step -1 ' Modulo 5
    Print i; "mod 5 =";: Locate , 18: Print Steve_ModX(i, 5), , Pete_modx(i, 5)
Next
Print "----------------------Negative Mods----------------------"
For i = 10 To -10 Step -1 ' Modulo -5
    Print i; "mod -5 =";: Locate , 18: Print Steve_ModX(i, -5), , Pete_modx(i, -5)
Next

Function Pete_modx (i, j)
    Pete_modx = (Abs(i) - Abs(j) * ((Abs(i) \ Abs(j)) + (1 - Sgn(i)) \ 2)) * Sgn(i Mod j)
End Function

Function Steve_ModX (num1, num2)
    Steve_ModX = ((num1 Mod num2) + Abs(num2)) Mod num2
End Function
Reply
#39
Cool! The two Forum muftis in competition.

I just use Julia for that. . . I also installed it because the name turned me on so much.  Heart

[Image: Julia2022-11-29.jpg]
Reply
#40
Nice! That's a keeper.

I wish I had your math teacher in high school. Well, not really. Mine had big boobs. She probably taught that MOD trick, but I probably missed it because I was too busy concentrating on the power of 2.

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 11 Guest(s)