Posts: 3,982
Threads: 178
Joined: Apr 2022
Reputation:
220
11-29-2022, 12:27 PM
(This post was last modified: 11-29-2022, 12:30 PM by bplus.)
Sorry forgot to get quote for next page, referring to this:
https://qb64phoenix.com/forum/showthread...9#pid10829
Not sure Steve_Mod of the third type will work with Singles, Doubles, _Floats with the Integer Division.
I see precision problems coming back to haunt us with decimal point numbers, the Reals, probably with Steve_Mod of the 2nd type.
b = b + ...
Posts: 1,000
Threads: 50
Joined: May 2022
Reputation:
27
(11-28-2022, 10:23 PM)Pete Wrote: 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"
. . .
Function Steve_ModX (num1, num2)
Steve_ModX = ((num1 Mod num2) + num2) Mod num2
End Function
This gives correct results. What I don't understand is why the program should be wrong because of an addendum? That way I can make any program skid.
Code: (Select All) Function Steve_ModX (num1, num2)
Steve_ModX = ((num1 Mod num2) + Abs(num2)) Mod num2
End Function
Steve_ModX = ((num1 Mod num2) + Abs(num2)) Mod num2
Posts: 2,183
Threads: 222
Joined: Apr 2022
Reputation:
104
Steve updated his function so it would match my routine's capability to work with both positive and negative modulos.
Pete
Posts: 1,000
Threads: 50
Joined: May 2022
Reputation:
27
(11-29-2022, 11:58 PM)Pete Wrote: Steve updated his function so it would match my routine's capability to work with both positive and negative modulos.
Pete Oh, and is that correct?
Posts: 2,697
Threads: 328
Joined: Apr 2022
Reputation:
217
(11-30-2022, 02:50 AM)Kernelpanic Wrote: (11-29-2022, 11:58 PM)Pete Wrote: Steve updated his function so it would match my routine's capability to work with both positive and negative modulos.
Pete Oh, and is that correct?
Is 2, or -2, the correct answer to SQR(4)?
BOTH are valid results. You just need to choose one or the other.
Posts: 301
Threads: 16
Joined: Apr 2022
Reputation:
51
that's both a two and a negative two for all you nobodies
Posts: 1,000
Threads: 50
Joined: May 2022
Reputation:
27
12-01-2022, 12:41 AM
(This post was last modified: 12-01-2022, 12:42 AM by Kernelpanic.)
(11-30-2022, 03:49 AM)SMcNeill Wrote: (11-30-2022, 02:50 AM)Kernelpanic Wrote: Oh, and is that correct?
Is 2, or -2, the correct answer to SQR(4)?
BOTH are valid results. You just need to choose one or the other.
Hmm, I do not know! This one: -9 MOD -5 = 1 looks to me: Divides integer with no remainder. Shows the number of b in a.
Code: (Select All) a = -9: b = -5
c = a \ b
Print c
I wrote a little program to explain this for myself.
Code: (Select All) 'Beispiele fuer MOD - 30. Nov. 2022
Option _Explicit
Dim As Integer a, b, c
Dim As Single f, fganz, frest
a = 13: b = 5
Print
'Liefert den Rest einer ganzzahligen Division
'Returns the remainder of an integer division
c = a Mod b
Print Using "MOD liefer den Rest von 13 MOD 5: ##"; c
Print
'Teilt ganzzahlig ohne Rest. Zeigt die Anzahl von b in a.
'Divides integer with no remainder. Returns the number of b in a.
c = a \ b
Print Using "Anzahl von 5 in 13: ## "; c
Print
'Mit Fliesskommazahlen
f = 7.456
frest = Abs(f - Fix(f))
fganz = f - frest
Print Using "Ganzzahl von 7.456: ##"; fganz
Print Using "Nachkommateil von 7.456: .###"; frest
Print
c = fganz Mod b
Print "Ganzzahl MOD b: ";
Print c
Print
c = Fix(f) Mod b
Print "Und das Ganze direkt mit Fix(f): ";
Print c
End
Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
What problem do You have with implementing a new function to QB64 in the form of:
MODn(y , x) = y - x * INT(y / x)
or
(y MODn x) = y - x * INT(y / x)
All it takes is a little good will. If no one has it, well...
As of today, the MOD is unusable.
Regards - Chris
Posts: 2,697
Threads: 328
Joined: Apr 2022
Reputation:
217
(12-03-2022, 08:19 AM)Chris Wrote: What problem do You have with implementing a new function to QB64 in the form of:
MODn(y , x) = y - x * INT(y / x)
What problem do you have in adding and implementing that function into your own code???
As of today, YOUR code is unusable. Nobody else is having any problem.
Posts: 2,183
Threads: 222
Joined: Apr 2022
Reputation:
104
12-03-2022, 09:06 AM
(This post was last modified: 12-03-2022, 09:06 AM by Pete.)
>>> MODn(y , x) = y - x * INT(y / x)
Another nice integer modula formula, but I'd tweak it to handle negative mods...
Code: (Select All) $CONSOLE:ONLY
x = 5
FOR y = 20 TO -20 STEP -1
PRINT y; MODn(y, x)
NEXT
FUNCTION MODn (y, x)
MODn = y - ABS(x) * INT(y / ABS(x))
END FUNCTION
Pete
|