Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
doubling a number
#8
There is indeed a limit to the number of digits, defined by decimal.MAX_PREC, which is 999.999.999.999.999.999 on 64-bit platforms. So on a system with 4 GB RAM the number of digits will be limited by the available RAM. But this will be the same with every other method you choose. This is not entirely true because we do not know how many times the data is copied internally (from string to decimal input -> to decimal output and back to string may need 4 times the number of bytes of the input string). But I guess the number of digits will not be more than some Millions and you have 4 Billions bytes of memory so I expect no problems.

About the other question, I found this example:
from decimal import localcontext

with localcontext() as ctx:
    ctx.prec = 42   # Perform a high precision calculation
    s = calculate_something()
s = +s  # Round the final result back to the default precision
It is explained in the manual.
Reply


Messages In This Thread
doubling a number - by Skaperen - Jul-15-2023, 04:55 PM
RE: doubling a number - by Gribouillis - Jul-15-2023, 07:08 PM
RE: doubling a number - by perfringo - Jul-16-2023, 08:36 AM
RE: doubling a number - by Gribouillis - Jul-16-2023, 03:56 PM
RE: doubling a number - by Skaperen - Jul-16-2023, 11:25 PM
RE: doubling a number - by ibreeden - Jul-17-2023, 08:39 AM
RE: doubling a number - by Skaperen - Jul-19-2023, 01:53 AM
RE: doubling a number - by ibreeden - Jul-19-2023, 06:41 AM
RE: doubling a number - by Skaperen - Jul-25-2023, 10:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020