Growl
-
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.
-
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 -
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:
-
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[^]
-
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
I don't think this is really wrong. This is probably due to confusion between modulo and remainder. There seems to be the same for positive numbers. But for negative numbers, there are different. Remainder work as expected. But modulo work as following: returns the difference of the first number, and the biggest integer (possibly negative) multiple of the second number that is less than the first number. So in our example: -1 - -20 = 19 That's why lot of programming languages have 2 "modulo" operators, one for modulo operations and one for remainder operations.
-
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
Doesn't say much.
-
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
Having given this some thought... I have come to the conclusion that the argument that the remainder must never be negative must make sense only to they who realllllly don't like improper fractions and consider negative fractions to be improper. But I have not found anything explaining why someone would feel that way. I have a guess, but no way to confirm it.
-
Signed (integer) division. Where your faith in the sanity of arithmetic first starts to crumble. Cheers, Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
Not at all; it's only when integer division is being simulated with floating-point division that things go wrong. But it's floating-point division's fault.