Skip to content

[1.21.1] Large overflowCount magnitude off by 2 #2000

@Fatmice

Description

@Fatmice

Base information

  • Minecraft version: 1.21.1
  • Mod version: 1.21
  • Minecraft Forge version: N/A
  • Mod Pack: N/A

Crash report

(If applicable)

Description / steps to reproduce

You stored overflowCount as multiples of Long.MAX_VALUE. So when you dipslay it for values greater than 975781955236953990712502012356953416011859675, you need to divide the value by BigInteger.TWO$^*$ if you are going to say they're multiples of 2^64. Otherwise, the resulting displayed figure will be twice as big as what's actually stored.

$^*$ Actually the factor to divide by is BigInteger.TWO x $(2^{63}-1)/2^{64}$ , but $(2^{63}-1)/2^{64} \approx 1$ so it's ignored.

For example:

        storageOP.overflowCount = new BigInteger("975781955236953990712502012356953416011859675234");
        storageOP.valueStorage = 4176350882083897343L;
        LOGGER.info(storageOP.getStoredBig());
        LOGGER.info(storageOP.overflowCount);
        NumberFormat decimalFormat = new DecimalFormat("0.######E0", DecimalFormatSymbols.getInstance(Locale.ROOT));
        LOGGER.info(decimalFormat.format(storageOP.overflowCount));
        LOGGER.info(storageOP.getReadable().getString());
        LOGGER.info(storageOP.getScientific());
        //Correct Magnitude 4.87891E47
        LOGGER.info(decimalFormat.format(storageOP.overflowCount.divide(BigInteger.TWO)));
  • Output
[11:22:27] [Test worker/INFO] [OPStorageOPTest/]: 9000000000000000000000000000000000000000000001146437782774984161181
[11:22:27] [Test worker/INFO] [OPStorageOPTest/]: 975781955236953990712502012356953416011859675234
[11:22:27] [Test worker/INFO] [OPStorageOPTest/]: 9.75782E47
[11:22:27] [Test worker/INFO] [OPStorageOPTest/]: 9.75782E47 x (2^64)
[11:22:27] [Test worker/INFO] [OPStorageOPTest/]: 9.75782E47 x (2^64) OP
[11:22:27] [Test worker/INFO] [OPStorageOPTest/]: 4.87891E47

Corrections:

        if (overflowCount.compareTo(prefixEnd) > 0) {
            return Component.literal(decimalFormat.format(overflowCount.divide(BigInteger.TWO)) + " x (2^64)");
        }
        if (overflowCount.compareTo(prefixEnd) > 0) {
            return decimalFormat.format(overflowCount.divide(BigInteger.TWO)) + " x (2^64) OP";
        }
  • Output with corrections:
[12:19:38] [Test worker/INFO] [OPStorageOPTest/]: 9000000000000000000000000000000000000000000001146437782774984161181
[12:19:38] [Test worker/INFO] [OPStorageOPTest/]: 975781955236953990712502012356953416011859675234
[12:19:38] [Test worker/INFO] [OPStorageOPTest/]: 9.75782E47
[12:19:38] [Test worker/INFO] [OPStorageOPTest/]: 4.87891E47 x (2^64)
[12:19:38] [Test worker/INFO] [OPStorageOPTest/]: 4.87891E47 x (2^64) OP
[12:19:38] [Test worker/INFO] [OPStorageOPTest/]: 4.87891E47

https://github.com/Draconic-Inc/Draconic-Evolution/blame/d297c2657cefa6ac2af19a96ee12a51ab07d36f5/src/main/java/com/brandon3055/draconicevolution/lib/OPStorageOP.java#L284
https://github.com/Draconic-Inc/Draconic-Evolution/blame/d297c2657cefa6ac2af19a96ee12a51ab07d36f5/src/main/java/com/brandon3055/draconicevolution/lib/OPStorageOP.java#L321

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions