Ankündigung

Einklappen
Keine Ankündigung bisher.

Baustein: operator syntax

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Baustein: operator syntax

    Hi,

    How could I get the remainder of a division ?
    Usually it is something like "mod" or "modulo".
    I looked in HS2-Doku-Logiksprache.pdf, it's not mentionned. The documents says:
    Weitere Operatoren findet man in der Python-Dokumentation unter:



    So I reach

    The following tokens are operators:
    And then ???
    Where can I find an explanation of the tokens with a small example ?
    I tried the >> (right shift), seems not to work, unless I use the wrong syntax

    Thank you for your help

    PS: do I need to import the math lib for this ?

    #2
    Hi Raymond,

    do you need a ready-to-use module or the code? Try this:

    5012|1|"EN[2]==0"|"1" |""|3|0|0|0
    5012|0|"1" |"EN[1] // EN[2]" |""|1|0|1|0
    5012|0|"1" |"EN[1] % EN[2]" |""|2|0|0|
    Angehängte Dateien
    Gruß, Rainer

    Kommentar


      #3
      Hello Raymond,

      '%' is the modulo operator

      Cheers,
      Gaston

      Kommentar


        #4
        Hi,

        There is so much documentation about Python on the net, that you can find it instantly in google by searching "python modulo"

        Kind regards,

        Jean-François

        Kommentar


          #5
          @Taxus
          Thank you very much for this practical example. In the mean time, I've done it manually, it's not a very nice code , now I can clean it

          @Gaston
          Merci
          I'm still a bit confused about the functions/operators that are supported "standard" (those that are mentionned in the DaCom doc) and those that require the import of the math lib. Any hint ?

          @Jef2000
          The question was more specifically about how to find my way in this particular doc. If DaCom points to that document, I guess there must be reason to do so.
          Is the >> supposed to work ?

          Kommentar


            #6
            Zitat von Warichet Beitrag anzeigen
            Is the >> supposed to work ?
            The >> operator does a right shift. And right shifting a number of 1 position divides the number by two (integer division). That has nothing to do with the modulo. If you want to compute x modulo "a power of 2", you can just perform a bit mask on the number. E.g. "x modulo 4" can be computed with "x | 3" but I don't see any good reason not to use the modulo operator provided by python ==> "x % 4"

            Kind regards,

            Jean-François

            Kommentar


              #7
              Zitat von Warichet Beitrag anzeigen
              @Gaston
              Merci
              I'm still a bit confused about the functions/operators that are supported "standard" (those that are mentionned in the DaCom doc) and those that require the import of the math lib. Any hint ?
              Its quite easy in fact. The modules do use there proper format as described by the Dacom manual. The three expressions in the 5012 lines (condition, expression, time expression) are python expressions. So anything that could be assiged to a python variable goes here.

              There is only one whay to understand what is comming standard and from which library other functions come, its learning how python works.

              The documentation, tutorials and beginner guides can be found here: http://www.python.org/doc/

              The library reference guide gives the functions from the different libraries.

              Regards,
              Gaston

              Kommentar


                #8
                Hi Gaston,

                Zitat von Gaston Beitrag anzeigen
                The documentation, tutorials and beginner guides can be found here: http://www.python.org/doc/
                Thank you for the pointer.
                I remember to have used this doc before, but lost the pointer to it .
                Heck, not pythonning every day

                Kommentar

                Lädt...
                X