0

Why the outputs of python and vb.net are different, the python result is the correct and expected output. Vb.net gives a wrong answer. how to rectify this? option strict on.

lm = -32617584047406127887053860912668548655625778953140441154984154756096705713545

Pcurve = 115792089237316195423570985008687907853269984665640564039457584007908834671663

Python

tempreturn = lm % Pcurve

Python result: 83174505189910067536517124096019359197644205712500122884473429251812128958118

VB.net

Dim tempreturn As BigInteger = lm Mod Pcurve

VB.net Result: -32617584047406127887053860912668548655625778953140441154984154756096705713545

  • Just from curiosity I ran this calculation on octave online compiler (https://octave-online.net/), the answer is similar to VB.NET. ans = -3.2618e+76 – Jonathan Applebaum Apr 16 '20 at 19:28
  • @jonathana: yes, I got the same answer from a online calculator. but try python code it gives a different answer and that is what I needed. I can't understand how come these languages give different answers. – Pretty Girl Apr 16 '20 at 19:33
  • But look, online python compilers gives the above answer different from vb.net and calculators https://repl.it/repls/PitifulSqueakyCircles – Pretty Girl Apr 16 '20 at 19:36
  • I assume negative modulus is unusual in various programming languages, google search for "modulo negative numbers" returning interesting results. anyway I think you need to ask this question here: https://math.stackexchange.com/ – Jonathan Applebaum Apr 16 '20 at 19:45
  • @jonathana: It's still a relevant programming question, because different languages handle mod operators differently. The math stack exchange may not know about those differences. – Sean Skelly Apr 16 '20 at 19:48
  • [What is the result of % in Python?](https://stackoverflow.com/questions/4432208/what-is-the-result-of-in-python) – Jimi Apr 16 '20 at 19:54
  • *"I can't understand how come these languages give different answers"*. Given that that difference is explained in various places online, you just gave away that you did no research before posting, which is always a no-no. – jmcilhinney Apr 17 '20 at 02:45
  • Does this answer your question? [The modulo operation on negative numbers in Python](https://stackoverflow.com/questions/3883004/the-modulo-operation-on-negative-numbers-in-python) – TnTinMn Apr 17 '20 at 02:56

1 Answers1

1

In .NET, the modulus operator is not a true modulus; it's only a remainder calculation. From documentation:

Returns: The remainder that results from the division.

If you want a 'truer' mod function, try this:

Dim tempreturn as BigInteger = ((lm Mod Pcurve) + Pcurve) Mod Pcurve
Sean Skelly
  • 1,229
  • 7
  • 13