• Hey! Register here to create your account, engage with the community, and talk about what is new!

Number Size Limits

Status
Not open for further replies.

K_Sasha

Active member
Joined
Aug 16, 2020
Messages
40
Reaction score
45
This thread explains how DiamondFire's number system works, and how large numbers can get before they stop working as expected.


Number Size Limits

The maximum number sizes are listed here. All limits also apply to negative numbers.
  • Value limit: 9,223,372,036,854,775 (number variables cannot store values larger than this)
Math operations have their own limits, and to function as expected they must satisfy these conditions.
  • Addition limit: x + y ≤ 9,223,372,036,854,775
  • Subtraction limit: x - y ≤ 9,223,372,036,854,775
  • Multiplication limit: x * y ≤ 9,223,372,036,854
  • Division limit: x / y; x ≤ 9,223,372,036,854
  • Modulus limit: None


How it Works

DiamondFire uses fixed point decimals to avoid rounding errors, and very long decimal numbers that are unpleasant to look at. Normally, in computer programming, floating point decimals are used. Floating point decimals vary the amount of decimal places that are stored depending on the size of the whole number, while fixed point decimals maintain a constant number of decimal places. Floating point decimals effectively store numbers in scientific notation.

DiamondFire implements fixed decimals by storing decimal numbers as integers, and then dividing by 1000 (and converting it to a Java decimal number) whenever the actual value is needed. To do this, DiamondFire uses 64 bit integer numbers, resulting in the limit of 2^63 (one bit is used for determining if the number is negative). This strategy requires us to make some adjustments when numbers are multiplied or divided, otherwise the result would come out 1000 times larger, or 1000 times smaller than intended, which results in some slightly different upper limits for those math operations.

And for clarity, here is how each math operation is done:

  • Storage limit: This is derived by dividing the 64 bit integer limit (2^63) by 1000: 9,223,372,036,854,775,807 / 1000
  • Addition: x + y
  • Subtraction: x - y
  • Multiplication: x * y / 1000
  • Division: x * 1000 / y
  • Modulus: x % y
  • Exponents, logarithms, and roots: These math operations are achieved by converting numbers to Java decimals to take advantage of Java's math functions.
 
Status
Not open for further replies.
Top Bottom