32 bit or 64 bit?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ram.rachum@gmail.com

    32 bit or 64 bit?

    Quick question:
    I have python code that does a lot of floating point arithmetic. How
    do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
    I'll install a 64-bit operating system, will that do the trick?
  • Peter Otten

    #2
    Re: 32 bit or 64 bit?

    ram.rachum@gmai l.com wrote:
    Quick question:
    I have python code that does a lot of floating point arithmetic. How
    do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
    I'll install a 64-bit operating system, will that do the trick?
    The Python float type uses a C double internally which is 64 bit even on 32
    bit CPUs.

    Peter

    Comment

    • ram.rachum@gmail.com

      #3
      Re: 32 bit or 64 bit?

      On Jun 15, 2:48 pm, Peter Otten <__pete...@web. dewrote:
      ram.rac...@gmai l.com wrote:
      Quick question:
      I have python code that does a lot of floating point arithmetic. How
      do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
      I'll install a 64-bit operating system, will that do the trick?
      >
      The Python float type uses a C double internally which is 64 bit even on 32
      bit CPUs.
      >
      Peter
      Does it mean that even now it does arithmetic in 64 bit?
      I'm not getting enough precision. Is there any way to increase it?

      Ram.

      Comment

      • Peter Otten

        #4
        Re: 32 bit or 64 bit?

        ram.rachum@gmai l.com wrote:
        On Jun 15, 2:48 pm, Peter Otten <__pete...@web. dewrote:
        >ram.rac...@gma il.com wrote:
        Quick question:
        I have python code that does a lot of floating point arithmetic. How
        do I make it do the arithmetic in 64 bit? (I have a 64 bit CPU.) If
        I'll install a 64-bit operating system, will that do the trick?
        >>
        >The Python float type uses a C double internally which is 64 bit even on
        >32 bit CPUs.
        >>
        >Peter
        >
        Does it mean that even now it does arithmetic in 64 bit?
        Yes. See



        for details.
        I'm not getting enough precision. Is there any way to increase it?


        If by "not enough precision" you mean you are bothered by
        >>.1
        0.1000000000000 0001

        have a look at the decimal module, see

        Source code: Lib/decimal.py The decimal module provides support for fast correctly rounded decimal floating-point arithmetic. It offers several advantages over the float datatype: Decimal “is based...


        Peter

        Comment

        • Christian Heimes

          #5
          Re: 32 bit or 64 bit?

          ram.rachum@gmai l.com wrote:
          Does it mean that even now it does arithmetic in 64 bit?
          I'm not getting enough precision. Is there any way to increase it?
          Buy a good book about numerics or take a course. ;)

          Seriously, computers and IEEE 754 floating point numbers have a lot of
          pit falls. If you chose the wrong algorithm you *will* get wrong
          results. With floats a*b*c and a*c*b can give you a different result.

          The decimal module is not an option if you need speed.

          Comment

          • ram.rachum@gmail.com

            #6
            Re: 32 bit or 64 bit?

            On Jun 15, 5:05 pm, Christian Heimes <li...@cheimes. dewrote:
            ram.rac...@gmai l.com wrote:
            Does it mean that even now it does arithmetic in 64 bit?
            I'm not getting enough precision. Is there any way to increase it?
            >
            Buy a good book about numerics or take a course. ;)
            >
            Seriously, computers and IEEE 754 floating point numbers have a lot of
            pit falls. If you chose the wrong algorithm you *will* get wrong
            results. With floats a*b*c and a*c*b can give you a different result.
            >
            The decimal module is not an option if you need speed.
            I do need speed. Is there an option?

            Comment

            • Christian Meesters

              #7
              Re: 32 bit or 64 bit?

              I do need speed. Is there an option?
              Mind telling us what you *actually* want to achieve? (What do you want to
              calculate?)

              Christian

              Comment

              • ram.rachum@gmail.com

                #8
                Re: 32 bit or 64 bit?

                On Jun 15, 6:58 pm, Christian Meesters <meest...@uni-mainz.dewrote:
                I do need speed. Is there an option?
                >
                Mind telling us what you *actually* want to achieve? (What do you want to
                calculate?)
                >
                Christian
                Physical simulations of objects with near-lightspeed velocity.

                Comment

                • Peter Otten

                  #9
                  Re: 32 bit or 64 bit?

                  ram.rachum@gmai l.com wrote:
                  On Jun 15, 6:58 pm, Christian Meesters <meest...@uni-mainz.dewrote:
                  I do need speed. Is there an option?
                  >>
                  >Mind telling us what you *actually* want to achieve? (What do you want to
                  >calculate?)
                  >>
                  >Christian
                  >
                  Physical simulations of objects with near-lightspeed velocity.
                  How did you determine that standard python floats are not good enough?
                  Everything beyond that is unlikely to be supported by the hardware and will
                  therefore introduce a speed penalty.

                  Did you try gmpy?

                  Peter

                  Comment

                  • Christian Meesters

                    #10
                    Re: 32 bit or 64 bit?

                    Peter Otten wrote:
                    >
                    How did you determine that standard python floats are not good enough?
                    Everything beyond that is unlikely to be supported by the hardware and
                    will therefore introduce a speed penalty.
                    >
                    Did you try gmpy?
                    I would like to add: If Python's precision (or that of additional modules)
                    won't do it for you, look around what other people in the physics community
                    are using.

                    Christian

                    Comment

                    • ram.rachum@gmail.com

                      #11
                      Re: 32 bit or 64 bit?

                      On Jun 15, 7:43 pm, Peter Otten <__pete...@web. dewrote:
                      ram.rac...@gmai l.com wrote:
                      On Jun 15, 6:58 pm, Christian Meesters <meest...@uni-mainz.dewrote:
                      I do need speed. Is there an option?
                      >
                      Mind telling us what you *actually* want to achieve? (What do you want to
                      calculate?)
                      >
                      Christian
                      >
                      Physical simulations of objects with near-lightspeed velocity.
                      >
                      How did you determine that standard python floats are not good enough?
                      I have a physical system set up in which a body is supposed to
                      accelerate and to get very close to lightspeed, while never really
                      attaining it. After approx. 680 seconds, Python gets stuck and tells
                      me the object has passed lightspeed. I put the same equations in
                      Mathematica, again I get the same mistake around 680 seconds. So I
                      think, I have a problem with my model! Then I pump up the
                      WorkingPrecisio n in Mathematica to about 10. I run the same equations
                      again, and it works! At least for the first 10,000 seconds, the object
                      does not pass lightspeed.
                      I concluded that I need Python to work at a higher precision.
                      Everything beyond that is unlikely to be supported by the hardware and will
                      therefore introduce a speed penalty.
                      >
                      I have thought of that as well. However I have no choice. I must do
                      these calculations. If you know of any way that is supported by the
                      hardware, it will be terrific, but for now the slower things will have
                      to do.


                      Did you try gmpy?
                      Not yet: I was kind of set back when I saw their homepage was last
                      updated 2002. But I'll give it a try. You think it's the best thing
                      there is?

                      Thanks,
                      Ram.

                      Comment

                      • Peter Otten

                        #12
                        Re: 32 bit or 64 bit?

                        ram.rachum@gmai l.com wrote:
                        I have a physical system set up in which a body is supposed to
                        accelerate and to get very close to lightspeed, while never really
                        attaining it. After approx. 680 seconds, Python gets stuck and tells
                        me the object has passed lightspeed. I put the same equations in
                        Mathematica, again I get the same mistake around 680 seconds. So I
                        think, I have a problem with my model! Then I pump up the
                        WorkingPrecisio n in Mathematica to about 10. I run the same equations
                        again, and it works! At least for the first 10,000 seconds, the object
                        does not pass lightspeed.
                        That the values are possible doesn't mean that you can trust them.
                        I concluded that I need Python to work at a higher precision.
                        How is WorkingPrecisio n defined? Python floats have about 16 significant
                        digits in base 10, so at first glance I would guess that you switched to
                        a /lower/ precision.

                        But I've come to agree with Christian that it would be good to show your
                        model to a physics and/or numerical maths expert. Perhaps you can find a
                        way for the errors to cancel out rather than accumulate.

                        Peter

                        Comment

                        • casevh

                          #13
                          Re: 32 bit or 64 bit?

                          Not yet: I was kind of set back when I saw their homepage was last
                          updated 2002. But I'll give it a try. You think it's the best thing
                          there is?
                          >
                          Thanks,
                          Ram.
                          gmpy has moved to Google.



                          gmpy only support the basic floating point operations so it may not be
                          sufficient for your needs.

                          A couple alternatives:

                          1) mpmath is a pure-Python, arbitrary precision floating-point
                          package. It will be faster than Decimal but slower than gmpy.


                          2) Sage is an open-source mathematics software package. It uses Python
                          as it glue/scripting language. It includes support for MPFR, a
                          multiple-precision floating point library based on GMP. www.sagemath.org

                          casevh

                          Comment

                          • Mensanator

                            #14
                            Re: 32 bit or 64 bit?

                            On Jun 15, 12:10 pm, "ram.rac...@gma il.com" <ram.rac...@gma il.com>
                            wrote:
                            On Jun 15, 7:43 pm, Peter Otten <__pete...@web. dewrote:
                            >
                            ram.rac...@gmai l.com wrote:
                            On Jun 15, 6:58 pm, Christian Meesters <meest...@uni-mainz.dewrote:
                            I do need speed. Is there an option?
                            >
                            >Mind telling us what you *actually* want to achieve? (What do you want to
                            >calculate?)
                            >
                            >Christian
                            >
                            Physical simulations of objects with near-lightspeed velocity.
                            >
                            How did you determine that standard python floats are not good enough?
                            >
                            I have a physical system set up in which a body is supposed to
                            accelerate and to get very close to lightspeed, while never really
                            attaining it. After approx. 680 seconds, Python gets stuck and tells
                            me the object has passed lightspeed. I put the same equations in
                            Mathematica, again I get the same mistake around 680 seconds. So I
                            think, I have a problem with my model! Then I pump up the
                            WorkingPrecisio n in Mathematica to about 10. I run the same equations
                            again, and it works! At least for the first 10,000 seconds, the object
                            does not pass lightspeed.
                            I concluded that I need Python to work at a higher precision.
                            >
                            Everything beyond that is unlikely to be supported by the hardware and will
                            therefore introduce a speed penalty.
                            >
                            I have thought of that as well. However I have no choice. I must do
                            these calculations. If you know of any way that is supported by the
                            hardware, it will be terrific, but for now the slower things will have
                            to do.
                            >
                            Did you try gmpy?
                            >
                            Not yet: I was kind of set back when I saw their homepage was last
                            updated 2002.
                            Try looking here:



                            The developers have abandoned SourceForge.
                            But I'll give it a try. You think it's the best thing
                            there is?
                            I haven't tried everything, but it's very good.
                            You might also want to go to the GMP site itself
                            and get their manual. Likee anything else, your
                            results will be no better than your algorithms.
                            >
                            Thanks,
                            Ram.

                            Comment

                            • Terry Reedy

                              #15
                              Re: 32 bit or 64 bit?


                              <ram.rachum@gma il.comwrote in message
                              news:1257aa24-14fa-426e-8019-262984c70633@2g 2000hsn.googleg roups.com...
                              |How did you determine that standard python floats are not good enough?

                              | I have a physical system set up in which a body is supposed to
                              | accelerate and to get very close to lightspeed, while never really
                              |attaining it.

                              Just a thought. You might do better if you can rearrange your equations in
                              terms of c-v instead of v. Letting c=1, you cannot accutrately express
                              v = .99999999999999 999999
                              in Python, but can easily express
                              1-v = .00000000000000 000001.
                              And so on.

                              tjr




                              Comment

                              Working...