Standard representation for arbitrary size/precision numbers

• pbuk
In summary, there are a few different ways to represent numbers of arbitrary size or precision in a text file, JSON message, or variable. The most common standard is to use decimal or scientific notation, with the option to use a different format if needed for compatibility with certain parsers.
pbuk
Homework Helper
Gold Member
Is there a standard way of representing numbers of arbitrary size or precision for storage in a text file, JSON message, variable etc.?

I am thinking of representing integers as decimal strings e.g. "-12345678901234567" and floats as an ordered pair (array) of strings representing decimal mantissa and exponent e.g. ["-1.2345678901234567", "17"], but if there is some existing standard I would rather follow that.

Short answer: depends on what the text file is for.

Just for any old text file, the standard form is as decimal or scientific notation.
Usually an e is used between mantissa and exponent where x10^ is not available.

The only reasons to depart from them is if the text file must be parsed by something that cannot cope with the numbers - in which case you use the format recognized by the parser.

Thanks, JavaScript in particular is going to have problems with big integers or high precision numbers so I think I will invoke the "format recognised by the parser" pattern.

1. What is a standard representation for arbitrary size/precision numbers?

A standard representation for arbitrary size/precision numbers is a method for representing numbers of any size or precision using a fixed number of bits. This allows for efficient storage and manipulation of numbers in computer systems.

2. How does a standard representation for arbitrary size/precision numbers work?

A standard representation for arbitrary size/precision numbers typically uses a combination of a sign bit, an exponent, and a mantissa to represent a number. The sign bit indicates whether the number is positive or negative, the exponent specifies the magnitude of the number, and the mantissa contains the digits of the number.

3. What are the advantages of using a standard representation for arbitrary size/precision numbers?

One advantage is that it allows for efficient storage and manipulation of numbers of any size or precision in computer systems. Additionally, it eliminates the need for different representations for different sizes or precisions of numbers, making calculations and comparisons easier.

4. Are there any limitations to using a standard representation for arbitrary size/precision numbers?

One limitation is that the precision of the number is limited by the number of bits used for the mantissa. This means that very large or very small numbers may lose precision when represented in this way. Additionally, not all numbers can be represented exactly in this format, leading to rounding errors.

5. How is a standard representation for arbitrary size/precision numbers used in real-world applications?

Standard representations for arbitrary size/precision numbers are used extensively in computer systems and programming languages for various applications such as scientific and financial calculations, data storage and transfer, and cryptography. They allow for efficient and accurate handling of numbers of any size or precision.

Replies
32
Views
2K
Replies
4
Views
1K
Replies
4
Views
1K
Replies
9
Views
1K
Replies
21
Views
6K
Replies
6
Views
2K
Replies
1
Views
2K
Replies
1
Views
1K
Replies
87
Views
6K
Replies
1
Views
3K