splitting a long token across lines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nakamura

    splitting a long token across lines

    Hi all,

    Say, I have a very long integer constant , how can
    I split across lines ?
    I tried something like
    MODULUS = 756756756756756 756756756756756 7\
    756750754654698 609486098609486 0\
    234564698659869 586954849869898 9\
    ...
    but it doesn't compile.
    Is there another way to write a long numeric constant besides writing
    it as a string and then converting to long? I also wouldn't like to put
    it all on one very long line.

    Thanks!
  • Elaine Jackson

    #2
    Re: splitting a long token across lines

    why can't you just write it like this:

    MODULUS = A*pow(10,a) + \
    B*pow(10,b) + \
    C

    "Nakamura" <lambajan@yahoo .com> wrote in message
    news:ef0c9173.0 404032349.742f5 9e6@posting.goo gle.com...
    | Hi all,
    |
    | Say, I have a very long integer constant , how can
    | I split across lines ?
    | I tried something like
    | MODULUS = 756756756756756 756756756756756 7\
    | 756750754654698 609486098609486 0\
    | 234564698659869 586954849869898 9\
    | ...
    | but it doesn't compile.
    | Is there another way to write a long numeric constant besides writing
    | it as a string and then converting to long? I also wouldn't like to put
    | it all on one very long line.
    |
    | Thanks!


    Comment

    • djw

      #3
      Re: splitting a long token across lines

      Nakamura wrote:[color=blue]
      > Hi all,
      >
      > Say, I have a very long integer constant , how can
      > I split across lines ?
      > I tried something like
      > MODULUS = 756756756756756 756756756756756 7\
      > 756750754654698 609486098609486 0\
      > 234564698659869 586954849869898 9\
      > ...
      > but it doesn't compile.
      > Is there another way to write a long numeric constant besides writing
      > it as a string and then converting to long? I also wouldn't like to put
      > it all on one very long line.
      >
      > Thanks![/color]

      Well, I _suppose_ you could do this:


      MODULUS = "75675675675675 675675675675675 67"\
      756750754654698 609486098609486 0"\
      234564698659869 586954849869898 9"\
      ...

      MODULUS = int(MODULUS)

      I'm sure I'm going to have to take some flak for this, though. I
      wouldn't do it. What's wrong with really long lines? Anything you do
      that I can see is going to obscure your code.

      -D

      Comment

      • djw

        #4
        Re: splitting a long token across lines

        djw wrote:
        [color=blue]
        > Nakamura wrote:
        >[color=green]
        >> Hi all,
        >>
        >> Say, I have a very long integer constant , how can
        >> I split across lines ?
        >> I tried something like
        >> MODULUS = 756756756756756 756756756756756 7\
        >> 756750754654698 609486098609486 0\
        >> 234564698659869 586954849869898 9\
        >> ...
        >> but it doesn't compile.
        >> Is there another way to write a long numeric constant besides writing
        >> it as a string and then converting to long? I also wouldn't like to put
        >> it all on one very long line.
        >>
        >> Thanks![/color]
        >
        >
        > Well, I _suppose_ you could do this:
        >
        >
        > MODULUS = "75675675675675 675675675675675 67"\
        > 756750754654698 609486098609486 0"\
        > 234564698659869 586954849869898 9"\
        > ...
        >
        > MODULUS = int(MODULUS)
        >
        > I'm sure I'm going to have to take some flak for this, though. I
        > wouldn't do it. What's wrong with really long lines? Anything you do
        > that I can see is going to obscure your code.
        >
        > -D[/color]

        Oops, I forgot some quotation marks there, but you get the idea.

        -D

        Comment

        • Josiah Carlson

          #5
          Re: splitting a long token across lines

          > MODULUS = 756756756756756 756756756756756 7\[color=blue]
          > 756750754654698 609486098609486 0\
          > 234564698659869 586954849869898 9\
          > ...[/color]

          Seems that you cannot use line continuation for integers. Unfortunate.

          However, using strings to store the value, then later converting it
          doesn't incur a significant overhead, as long as you are only
          initializing MODULUS once.

          MODULUS = '75675675675675 675675675675675 67'\
          '75675075465469 860948609860948 60'\
          '23456469865986 958695484986989 89'\
          ...

          MODULUS = int(MODULUS)

          - Josiah

          Comment

          Working...