Dealing with 1000 digit numbers

Click For Summary

Discussion Overview

The discussion revolves around handling large numbers, specifically 1000-digit numbers, in programming environments such as Octave, Matlab, and Python. Participants explore issues related to numerical representation limits and precision challenges, seeking solutions and workarounds without relying on external toolkits.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes difficulties with numbers exceeding the maximum representable value in binary64 or float64 formats, suggesting that there may be basic methods for handling this issue.
  • Another participant mentions the availability of libraries for arbitrary precision arithmetic in C and Python, specifically referencing mpmath and GMP.
  • A suggestion is made that Julia can handle large numbers effectively, drawing a parallel to Matlab.
  • One participant proposes representing large numbers by separating the mantissa and exponent, or using logarithmic representation to manage large magnitudes.
  • Another approach discussed involves representing numbers as fractions to avoid precision issues, with a recommendation to apply Euclid's algorithm for simplification.
  • A further suggestion is made to develop an arithmetic package that processes numeric strings for handling very large numbers, revisiting traditional computational methods.
  • For performance concerns with extremely large numbers, one participant advocates for using the GMP library over numeric strings.

Areas of Agreement / Disagreement

Participants express a range of views on how to handle large numbers and precision issues, with no consensus on a single solution or method. Multiple competing approaches and suggestions are presented, indicating an unresolved discussion.

Contextual Notes

Participants highlight limitations related to numerical representation and precision, but do not resolve the underlying mathematical complexities or assumptions involved in their proposed solutions.

Snowmachine
Messages
4
Reaction score
2
Hi,
Mostly i work with Octave / Matlab but i am trying to get into python also.
Lately i have a couple problems where my numbers can't be represented in binary64 or float64 default format because they exceed the max of 1.8x10^308. Is there a common way people deal with this (without toolkits)?

Similarly i have some problems where i need more than 15 digits of precision after the decimal and sometimes this exceeds the default precision. For example if i specify "precision", 56 on [1/3] the 0.(3) repeating 3s eventualy turn into non-3s which is a digital artifact.

Any suggestions or workarounds to these problems in matlab/octave or python? (Without toolkit$?) I feel like there may be something basic I am missing because it seems like this should be straightforward.
Thanks!
 
Technology news on Phys.org
  • Like
Likes   Reactions: jedishrfu
  • Like
Likes   Reactions: jedishrfu
Thanks for the tips guys, I'll dig into these options.
 
  • Like
Likes   Reactions: berkeman and jedishrfu
Snowmachine said:
Lately i have a couple problems where my numbers can't be represented in binary64 or float64 default format because they exceed the max of 1.8x10^308.
If the huge absolute magnitude of the exponent is the problem, then you should consider carrying the mantissa in a float64, with the exponent as an integer in a second variable. Another technique is to represented the numbers as logarithms.

Snowmachine said:
Similarly i have some problems where i need more than 15 digits of precision after the decimal and sometimes this exceeds the default precision. For example if i specify "precision", 56 on [1/3] the 0.(3) repeating 3s eventualy turn into non-3s which is a digital artifact.
If each number is represented by a fraction, the ratio of two integers, then the implicit division that generates the artefact does not have to be executed until human readable output requires long division. You will get good at fraction arithmetic. You may need to apply Euclid's algorithm to simplify the fractions.

Both problems can also be solved by writing an arithmetic package that processes strings of numeric characters. Maybe keep the position of the decimal points in signed integer variables. There are many digit-by-digit computational methods available. You will get to revisit long multiplication, division and root extraction as used by the great human computers of the past.

If you really need speed, or have numbers with more than 10k digits, you should go for the gmp lib, rather than numeric strings.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 55 ·
2
Replies
55
Views
11K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
6K