Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Operator MOD
#51
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 + ...
Reply
#52
(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
Reply
#53
Steve updated his function so it would match my routine's capability to work with both positive and negative modulos.

Pete
Reply
#54
(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?  Huh

[Image: MOD-Negative-Zahlen2022-11-29.jpg]
Reply
#55
(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?  Huh

[Image: MOD-Negative-Zahlen2022-11-29.jpg]


Is 2, or -2, the correct answer to SQR(4)?

BOTH are valid results.  You just need to choose one or the other.  Wink
Reply
#56
that's both a two and a negative two for all you nobodies
Reply
#57
(11-30-2022, 03:49 AM)SMcNeill Wrote:
(11-30-2022, 02:50 AM)Kernelpanic Wrote: Oh, and is that correct?  Huh

[Image: MOD-Negative-Zahlen2022-11-29.jpg]


Is 2, or -2, the correct answer to SQR(4)?

BOTH are valid results.  You just need to choose one or the other.  Wink

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
Reply
#58
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
Reply
#59
(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.
Reply
#60
>>> 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
Reply




Users browsing this thread: 3 Guest(s)