Growl
-
JavaScript backs up C# and says -1 too. The windows calculator (set on Programmer) also says -1. Wait... Python says 19. That's what Google is going by!! Python. Python is obviously wrong. EDIT Just tried it in C also and it says -1 so it is obvious that Google and Python are completely wrong. Why would anyone think different? EDIT 2 Just tried it in Java (actually in an Android app) and it gives -1. There should be an entire discussion on why Python chose the Euclidean definition (if that is in fact the reason) while every other language seems to have chosen -1. Interesting. EDIT 3 I can't stop now. I just tried it in Kotlin and it also results in -1. EDIT 4 Went all the way back to QuickBasic*, ok? And -1 MOD 20 is -1 like it should be!!! PRINT "HEllo" PRINT -1 MOD 20 * repl.it - online REPL, QBASIC Compiler & IDE[^] EDIT 5 Yep, I found another one that gives 19. It's Ruby!!!! Well, that sinks it, Google, Python and Ruby are all wrong for sure. :mad: We all know Python and Ruby are garbage languages and I'm sure this will be their end. :rolleyes: repl.it - online REPL, RUBY Compiler & IDE[^] EDIT 6 Tried it on the bash shell:
$ echo '-1%20' | bc
-1Also tried it on windows command prompt
set /a -1%20
-1Well, I certainly hope you can see that when I beat a dead horse...I beat it soundly to death! :laugh:
PIEBALD boots up his MicroVAX and enters a darkened chamber...
VAX BASIC V3.9-000
Ready
PRINT MOD(-1,20)
-1
ReadyFor added points, Turbo BASIC (sorry, the color didn't come over):
┌──────────────────────────────── Turbo Basic ─────────────────────────────────┐
│ File Edit Run Compile Options Setup Window Debug │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────── Edit ────────────────────────────────┐┌ Trace ┐
│ E:NONAME.BAS Line 1 Col 19 Insert Indent Tab ││ │
│10 PRINT -1 MOD 20 ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└─────────────────────────────────────────────────────────────────────┘│ │
┌────────────── Message ───────────────┐╔════════════ Run ════════════╗│ │
│ Compiling: NONAME │║-1 ║│ │
│ Time: 00:00 │║ ║│ │
│ Line: 1 Stmt: 3 Free: 370k │║ ║│ │
│ │║ ║│ │
│ │║ ║│ │
└──────────────────────────────────────┘╚═════════════════════════════╝└───────┘
Alt-F5-Zoom Alt-F6-Next -
I doubt this is new. -1 % 20 Google says 19. C# says -1. :mad: [Some solutions and discussion.](https://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain) :mad::mad: Marc
Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Same discussion here, see answer 2:How to implement a circular counter?[^] For me the result of c# (-1) is also more intuitive if I look e.g. x % 2 around Zero... 1 % 2 = 0 * 2 rem: 1 0 % 2 = 0 * 2 rem: 0 -1% 2 = 0 * 2 rem: -1 ... which for me does Show a Kind of symetrie. I agree, a very unscientific Argumentation :-D Bruno
-
JavaScript backs up C# and says -1 too. The windows calculator (set on Programmer) also says -1. Wait... Python says 19. That's what Google is going by!! Python. Python is obviously wrong. EDIT Just tried it in C also and it says -1 so it is obvious that Google and Python are completely wrong. Why would anyone think different? EDIT 2 Just tried it in Java (actually in an Android app) and it gives -1. There should be an entire discussion on why Python chose the Euclidean definition (if that is in fact the reason) while every other language seems to have chosen -1. Interesting. EDIT 3 I can't stop now. I just tried it in Kotlin and it also results in -1. EDIT 4 Went all the way back to QuickBasic*, ok? And -1 MOD 20 is -1 like it should be!!! PRINT "HEllo" PRINT -1 MOD 20 * repl.it - online REPL, QBASIC Compiler & IDE[^] EDIT 5 Yep, I found another one that gives 19. It's Ruby!!!! Well, that sinks it, Google, Python and Ruby are all wrong for sure. :mad: We all know Python and Ruby are garbage languages and I'm sure this will be their end. :rolleyes: repl.it - online REPL, RUBY Compiler & IDE[^] EDIT 6 Tried it on the bash shell:
$ echo '-1%20' | bc
-1Also tried it on windows command prompt
set /a -1%20
-1Well, I certainly hope you can see that when I beat a dead horse...I beat it soundly to death! :laugh:
mandatory[^] ;P :laugh: :laugh: :laugh: Somehow I imagine you, searching all your external drives: "Where is this damn VM... I have to test this!!! ARRRRGGGG" :laugh: :laugh: :laugh: :laugh:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
PIEBALD boots up his MicroVAX and enters a darkened chamber...
VAX BASIC V3.9-000
Ready
PRINT MOD(-1,20)
-1
ReadyFor added points, Turbo BASIC (sorry, the color didn't come over):
┌──────────────────────────────── Turbo Basic ─────────────────────────────────┐
│ File Edit Run Compile Options Setup Window Debug │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────── Edit ────────────────────────────────┐┌ Trace ┐
│ E:NONAME.BAS Line 1 Col 19 Insert Indent Tab ││ │
│10 PRINT -1 MOD 20 ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└─────────────────────────────────────────────────────────────────────┘│ │
┌────────────── Message ───────────────┐╔════════════ Run ════════════╗│ │
│ Compiling: NONAME │║-1 ║│ │
│ Time: 00:00 │║ ║│ │
│ Line: 1 Stmt: 3 Free: 370k │║ ║│ │
│ │║ ║│ │
│ │║ ║│ │
└──────────────────────────────────────┘╚═════════════════════════════╝└───────┘
Alt-F5-Zoom Alt-F6-NextPIEBALDconsult wrote:
(sorry, the color didn't come over)
:doh: :doh: You could have posted a link to the screenshot, or code the color in HTML yourself :rolleyes: :rolleyes: :laugh: :laugh: :laugh: Jokes apart Turbo Basic is not unknown for me. But VAX? I never saw it Edit:
Quote:
VAX BASIC User Manual. Order Number: AA-HY158-TE. February 1990. This manual describes how to develop VAX BASIC programs, describes the features of
Ok... I think I already know why...
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
JavaScript backs up C# and says -1 too. The windows calculator (set on Programmer) also says -1. Wait... Python says 19. That's what Google is going by!! Python. Python is obviously wrong. EDIT Just tried it in C also and it says -1 so it is obvious that Google and Python are completely wrong. Why would anyone think different? EDIT 2 Just tried it in Java (actually in an Android app) and it gives -1. There should be an entire discussion on why Python chose the Euclidean definition (if that is in fact the reason) while every other language seems to have chosen -1. Interesting. EDIT 3 I can't stop now. I just tried it in Kotlin and it also results in -1. EDIT 4 Went all the way back to QuickBasic*, ok? And -1 MOD 20 is -1 like it should be!!! PRINT "HEllo" PRINT -1 MOD 20 * repl.it - online REPL, QBASIC Compiler & IDE[^] EDIT 5 Yep, I found another one that gives 19. It's Ruby!!!! Well, that sinks it, Google, Python and Ruby are all wrong for sure. :mad: We all know Python and Ruby are garbage languages and I'm sure this will be their end. :rolleyes: repl.it - online REPL, RUBY Compiler & IDE[^] EDIT 6 Tried it on the bash shell:
$ echo '-1%20' | bc
-1Also tried it on windows command prompt
set /a -1%20
-1Well, I certainly hope you can see that when I beat a dead horse...I beat it soundly to death! :laugh:
It is hard to say 'wrong' or 'right'... The Euclidean way is much more perfect (consistent) and fits better math as science, however Donald Knuth promoted an other way (called floored division), which found to be better for computer science and used by most languages today... Modulo operation - Wikipedia[^] - there is a nice table on the left side about programming languages...
Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.
-
I doubt this is new. -1 % 20 Google says 19. C# says -1. :mad: [Some solutions and discussion.](https://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain) :mad::mad: Marc
Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Someone pointed out this in the link you posted:
Quote:
Please note that C# and C++'s % operator is actually NOT a modulo, it's remainder.
Could it be that this is true? In that case making assumptions can have unexpected consequences. I'm going to look what the MSDN has to say about that... There you go:
Quote:
% Operator (C# Reference) The % operator computes the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators.
The user can't update the up: we update it for them (Choice in the CP poll)
-
PIEBALD boots up his MicroVAX and enters a darkened chamber...
VAX BASIC V3.9-000
Ready
PRINT MOD(-1,20)
-1
ReadyFor added points, Turbo BASIC (sorry, the color didn't come over):
┌──────────────────────────────── Turbo Basic ─────────────────────────────────┐
│ File Edit Run Compile Options Setup Window Debug │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────── Edit ────────────────────────────────┐┌ Trace ┐
│ E:NONAME.BAS Line 1 Col 19 Insert Indent Tab ││ │
│10 PRINT -1 MOD 20 ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└─────────────────────────────────────────────────────────────────────┘│ │
┌────────────── Message ───────────────┐╔════════════ Run ════════════╗│ │
│ Compiling: NONAME │║-1 ║│ │
│ Time: 00:00 │║ ║│ │
│ Line: 1 Stmt: 3 Free: 370k │║ ║│ │
│ │║ ║│ │
│ │║ ║│ │
└──────────────────────────────────────┘╚═════════════════════════════╝└───────┘
Alt-F5-Zoom Alt-F6-Next -
JavaScript backs up C# and says -1 too. The windows calculator (set on Programmer) also says -1. Wait... Python says 19. That's what Google is going by!! Python. Python is obviously wrong. EDIT Just tried it in C also and it says -1 so it is obvious that Google and Python are completely wrong. Why would anyone think different? EDIT 2 Just tried it in Java (actually in an Android app) and it gives -1. There should be an entire discussion on why Python chose the Euclidean definition (if that is in fact the reason) while every other language seems to have chosen -1. Interesting. EDIT 3 I can't stop now. I just tried it in Kotlin and it also results in -1. EDIT 4 Went all the way back to QuickBasic*, ok? And -1 MOD 20 is -1 like it should be!!! PRINT "HEllo" PRINT -1 MOD 20 * repl.it - online REPL, QBASIC Compiler & IDE[^] EDIT 5 Yep, I found another one that gives 19. It's Ruby!!!! Well, that sinks it, Google, Python and Ruby are all wrong for sure. :mad: We all know Python and Ruby are garbage languages and I'm sure this will be their end. :rolleyes: repl.it - online REPL, RUBY Compiler & IDE[^] EDIT 6 Tried it on the bash shell:
$ echo '-1%20' | bc
-1Also tried it on windows command prompt
set /a -1%20
-1Well, I certainly hope you can see that when I beat a dead horse...I beat it soundly to death! :laugh:
raddevus wrote:
Python and Ruby are garbage languages and I'm sure this will be their end.
I would also include some others like Javascript, but at least it knows its math and so it lives on (for now). -1%20 = 19 is so counter intuitive, I don't know how they reached that conclusion, however, we can see here that in Python the result of a modulo(%) operation has to be of the same sign and strictly smaller than the second operand. Edit: And so python says print 1%-20; = -19. print -1%-20; = -1. (finally) Someone needs to go back to the math class they hated.
I am not the one who knocks. I never knock. In fact, I hate knocking.
-
I doubt this is new. -1 % 20 Google says 19. C# says -1. :mad: [Some solutions and discussion.](https://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain) :mad::mad: Marc
Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
To make it even worse, it's not even the same in all languages, and to make *that* even worse there are languages that didn't even make a choice which way to do it (you have already guessed which languages that were). There's a nice list at the right side of the relevant [wikipedia page](https://en.wikipedia.org/wiki/Modulo\_operation), which is interestingly the *Modulo* operation page while the point is that in most languages it's really the remainder operation. This is all bullshit and programming sucks.
-
PIEBALD boots up his MicroVAX and enters a darkened chamber...
VAX BASIC V3.9-000
Ready
PRINT MOD(-1,20)
-1
ReadyFor added points, Turbo BASIC (sorry, the color didn't come over):
┌──────────────────────────────── Turbo Basic ─────────────────────────────────┐
│ File Edit Run Compile Options Setup Window Debug │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────── Edit ────────────────────────────────┐┌ Trace ┐
│ E:NONAME.BAS Line 1 Col 19 Insert Indent Tab ││ │
│10 PRINT -1 MOD 20 ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└─────────────────────────────────────────────────────────────────────┘│ │
┌────────────── Message ───────────────┐╔════════════ Run ════════════╗│ │
│ Compiling: NONAME │║-1 ║│ │
│ Time: 00:00 │║ ║│ │
│ Line: 1 Stmt: 3 Free: 370k │║ ║│ │
│ │║ ║│ │
│ │║ ║│ │
└──────────────────────────────────────┘╚═════════════════════════════╝└───────┘
Alt-F5-Zoom Alt-F6-Next -
JavaScript backs up C# and says -1 too. The windows calculator (set on Programmer) also says -1. Wait... Python says 19. That's what Google is going by!! Python. Python is obviously wrong. EDIT Just tried it in C also and it says -1 so it is obvious that Google and Python are completely wrong. Why would anyone think different? EDIT 2 Just tried it in Java (actually in an Android app) and it gives -1. There should be an entire discussion on why Python chose the Euclidean definition (if that is in fact the reason) while every other language seems to have chosen -1. Interesting. EDIT 3 I can't stop now. I just tried it in Kotlin and it also results in -1. EDIT 4 Went all the way back to QuickBasic*, ok? And -1 MOD 20 is -1 like it should be!!! PRINT "HEllo" PRINT -1 MOD 20 * repl.it - online REPL, QBASIC Compiler & IDE[^] EDIT 5 Yep, I found another one that gives 19. It's Ruby!!!! Well, that sinks it, Google, Python and Ruby are all wrong for sure. :mad: We all know Python and Ruby are garbage languages and I'm sure this will be their end. :rolleyes: repl.it - online REPL, RUBY Compiler & IDE[^] EDIT 6 Tried it on the bash shell:
$ echo '-1%20' | bc
-1Also tried it on windows command prompt
set /a -1%20
-1Well, I certainly hope you can see that when I beat a dead horse...I beat it soundly to death! :laugh:
-
I doubt this is new. -1 % 20 Google says 19. C# says -1. :mad: [Some solutions and discussion.](https://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain) :mad::mad: Marc
Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Eric Lippert discussed this back in 2011: What’s the difference? Remainder vs Modulus – Fabulous Adventures In Coding[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Well done :thumbsup:
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
-
It is hard to say 'wrong' or 'right'... The Euclidean way is much more perfect (consistent) and fits better math as science, however Donald Knuth promoted an other way (called floored division), which found to be better for computer science and used by most languages today... Modulo operation - Wikipedia[^] - there is a nice table on the left side about programming languages...
Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.
Kornfeld Eliyahu Peter wrote:
It is hard to say 'wrong' or 'right'
Yes, I agree... except of course the one that returns -1 is right. :) Just kidding. I really do agree.
Kornfeld Eliyahu Peter wrote:
Donald Knuth promoted an other way (called floored division), which found to be better for computer science and used by most languages today.
Very interesting and I agree that this version is better for computer science.
-
raddevus wrote:
Python and Ruby are garbage languages and I'm sure this will be their end.
I would also include some others like Javascript, but at least it knows its math and so it lives on (for now). -1%20 = 19 is so counter intuitive, I don't know how they reached that conclusion, however, we can see here that in Python the result of a modulo(%) operation has to be of the same sign and strictly smaller than the second operand. Edit: And so python says print 1%-20; = -19. print -1%-20; = -1. (finally) Someone needs to go back to the math class they hated.
I am not the one who knocks. I never knock. In fact, I hate knocking.
-
mandatory[^] ;P :laugh: :laugh: :laugh: Somehow I imagine you, searching all your external drives: "Where is this damn VM... I have to test this!!! ARRRRGGGG" :laugh: :laugh: :laugh: :laugh:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
Yes, that's it!!
Nelek wrote:
I imagine you, searching all your external drives: "Where is this damn VM... I have to test this!!! ARRRRGGGG"
:laugh: That's pretty much how it went. I used the GCC for the C version -- but had to log into my DigitalOcean droplet because it was easiest to write a command line C program there. I used my GIT bash shell to do the the bash shell one, etc. I was searching all over the Internet for compiler VMs. :) I actually tried to get it running in ADA, but couldn't. :( :laugh:
-
PIEBALD boots up his MicroVAX and enters a darkened chamber...
VAX BASIC V3.9-000
Ready
PRINT MOD(-1,20)
-1
ReadyFor added points, Turbo BASIC (sorry, the color didn't come over):
┌──────────────────────────────── Turbo Basic ─────────────────────────────────┐
│ File Edit Run Compile Options Setup Window Debug │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────── Edit ────────────────────────────────┐┌ Trace ┐
│ E:NONAME.BAS Line 1 Col 19 Insert Indent Tab ││ │
│10 PRINT -1 MOD 20 ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└─────────────────────────────────────────────────────────────────────┘│ │
┌────────────── Message ───────────────┐╔════════════ Run ════════════╗│ │
│ Compiling: NONAME │║-1 ║│ │
│ Time: 00:00 │║ ║│ │
│ Line: 1 Stmt: 3 Free: 370k │║ ║│ │
│ │║ ║│ │
│ │║ ║│ │
└──────────────────────────────────────┘╚═════════════════════════════╝└───────┘
Alt-F5-Zoom Alt-F6-Next -
PIEBALDconsult wrote:
(sorry, the color didn't come over)
:doh: :doh: You could have posted a link to the screenshot, or code the color in HTML yourself :rolleyes: :rolleyes: :laugh: :laugh: :laugh: Jokes apart Turbo Basic is not unknown for me. But VAX? I never saw it Edit:
Quote:
VAX BASIC User Manual. Order Number: AA-HY158-TE. February 1990. This manual describes how to develop VAX BASIC programs, describes the features of
Ok... I think I already know why...
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
Unlike the newer DEC/COMPAQ/HP BASIC that I have on my AlphaServers and Itanium, VAX BASIC still has immediate mode. :-D
-
I doubt this is new. -1 % 20 Google says 19. C# says -1. :mad: [Some solutions and discussion.](https://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain) :mad::mad: Marc
Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Apparently ADA has both: AdaModRem.png[^] VAX C (being normal), has this: VaxCModRem.png[^]