Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Growl

Growl

Scheduled Pinned Locked Moved The Lounge
csharppythoncsscomdiscussion
28 Posts 14 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P PIEBALDconsult

    PIEBALD boots up his MicroVAX and enters a darkened chamber...

    VAX BASIC V3.9-000

    Ready

    PRINT MOD(-1,20)
    -1
    Ready

    For 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

    E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #13

    :thumbsup::cool:

    Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

    1 Reply Last reply
    0
    • R raddevus

      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
      -1

      Also tried it on windows command prompt

      set /a -1%20
      -1

      Well, I certainly hope you can see that when I beat a dead horse...I beat it soundly to death! :laugh:

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #14

      Well done :thumbsup:

      Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

      R 1 Reply Last reply
      0
      • M Marc Clifton

        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

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #15

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        P 1 Reply Last reply
        0
        • E Eytukan

          Well done :thumbsup:

          Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

          R Offline
          R Offline
          raddevus
          wrote on last edited by
          #16

          Thanks

          1 Reply Last reply
          0
          • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

            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.

            R Offline
            R Offline
            raddevus
            wrote on last edited by
            #17

            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.

            1 Reply Last reply
            0
            • G GKP1992

              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.

              R Offline
              R Offline
              raddevus
              wrote on last edited by
              #18

              GKP1992 wrote:

              -1%20 = 19 is so counter intuitive,

              I agree. It is interesting that a small number of languages use this different way which is maybe more loyal to math.

              1 Reply Last reply
              0
              • P PIEBALDconsult

                PIEBALD boots up his MicroVAX and enters a darkened chamber...

                VAX BASIC V3.9-000

                Ready

                PRINT MOD(-1,20)
                -1
                Ready

                For 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

                R Offline
                R Offline
                raddevus
                wrote on last edited by
                #19

                Fantastic!! I'm actually literally LOLing. :laugh: :laugh: :laugh:

                enhzflepE 1 Reply Last reply
                0
                • N Nelek

                  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.

                  R Offline
                  R Offline
                  raddevus
                  wrote on last edited by
                  #20

                  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:

                  1 Reply Last reply
                  0
                  • N Nelek

                    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.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #21

                    Unlike the newer DEC/COMPAQ/HP BASIC that I have on my AlphaServers and Itanium, VAX BASIC still has immediate mode. :-D

                    1 Reply Last reply
                    0
                    • R raddevus

                      Fantastic!! I'm actually literally LOLing. :laugh: :laugh: :laugh:

                      enhzflepE Offline
                      enhzflepE Offline
                      enhzflep
                      wrote on last edited by
                      #22

                      Bewdy, had hoped I wouldn't be the only one prepared to admit it. :-\

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        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

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #23

                        Apparently ADA has both: AdaModRem.png[^] VAX C (being normal), has this: VaxCModRem.png[^]

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          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

                          P Offline
                          P Offline
                          pth14
                          wrote on last edited by
                          #24

                          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.

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            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

                            A Offline
                            A Offline
                            Ancandune
                            wrote on last edited by
                            #25

                            Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
                            [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
                            Type "help", "copyright", "credits" or "license" for more information.

                            import math
                            math.fmod(-1,20)
                            -1.0

                            1 Reply Last reply
                            0
                            • Richard DeemingR Richard Deeming

                              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

                              P Offline
                              P Offline
                              PIEBALDconsult
                              wrote on last edited by
                              #26

                              Doesn't say much.

                              1 Reply Last reply
                              0
                              • M Marc Clifton

                                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

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #27

                                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.

                                1 Reply Last reply
                                0
                                • P Peter_in_2780

                                  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

                                  P Offline
                                  P Offline
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #28

                                  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.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups