Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I make the decimal go on?

  1. Oct 10, 2015 #1
    I was bored so I made this:

    print("Object vs. Planck Length")
    print("How long is the object in meters?")
    obj = int(input())
    result = obj - 0.000000000000000000000000000000000016162
    print("1 planck length is " + str(result) + " meters smaller than that object.")

    Problem is that the decimal doesn’t carry all the way to 16162. For example, I'll get the output:

    Object vs. Planck Length
    How long is the object in meters?
    4
    Planck Length is 4.0 smaller than that object.

    What would be the fix? Thanks.
     
  2. jcsd
  3. Oct 10, 2015 #2

    Orodruin

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member

    The question is why you would even want to do this computation. No length at the scale of a meter is going to be known to within one planck length and your program is therefore already correct in terms of possible significant digits. A more meaningful quantity would be the ratio.
     
  4. Oct 10, 2015 #3
    >shines light on you

    I said answer the question!
     
  5. Oct 10, 2015 #4

    Orodruin

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member

    Your number is far too small for the typical working precision to notice a difference from 4 - and for good reason - there are very few cases where you would actually want to take a difference between numbers with such different size.

    Also, remember that you are asking people to help you for free. An interrogative attitude such as the one you just displayed will only act to alienate the people you are asking for help.
     
  6. Oct 10, 2015 #5
    So is there or is there not anyway of accomplishing this?

    Protip: I was role playing in a non-threatening way to enlighten you. I did not succeed.
     
  7. Oct 10, 2015 #6

    jim mcnamara

    User Avatar

    Staff: Mentor

    This part is correct:
    The default level of precision for most computer languages using floating point operations (decimal arithmetic) on an X86 (windows/Linux desktop) is going to be 15 decimals. The answer here involves more than double that number.

    This part is an analogy since the idea of subtracting numbers like you did does not "work":
    You are subtracting the "length of an ant" from the "length" of a galaxy. The ant is lost in the calculation. So it does not make any logical sense to do what you are trying. Or as Orudruin said, the answer 4 is scientifically correct, since nothing can be measured simultaneously at those two different scales.

    If you insist on getting arithmetically correct answers (for a problem that does not make lots of sense to people who understand), use and install numpy, or if you have Linux try C and gmp. You need special software to handle the extra levels of precision correctly. So in effect you are giving up speedy calculations for much slower extended precision arithmetic operations.

    Paper and pencil works, too. Since you want to make this work, telling us your OS and what programming tools you are now using would help.
     
  8. Oct 11, 2015 #7

    Mark44

    Staff: Mentor

    I'm 100% with Orodruin here. Your request comes off as very demanding, which is NOT the way to convince people to spend time helping you. The appropriate attitude is "please help me" not "tell me now!".
     
  9. Oct 11, 2015 #8

    DaveC426913

    User Avatar
    Gold Member

    Cash, I got the intended meaning.
    But you probably mean to 'lighten the mood'. To 'enlighten a person' means something very different. :wink:

    Anyway, Cash, you'll want to ensure that the input and output are cast into "double precision" floating point decimals.
     
  10. Oct 11, 2015 #9

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    It looks like Python has a package to do calculations with a large number of significant digits. See http://pythonhosted.org/bigfloat/ The calculation you are trying requires 41 significant digits, It is far beyond what standard double precision calculations can do (15-17 significant digits)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook