Introduction
The purpose of BytePrimeCache
is to store prime numbers. Prime numbers are unlimited, but numerical representation on finite machines is severely limited.
A byte is a sequence of 8 bits, and is the smallest unit of numerical representation using machine memory. After the byte data type has been exhausted, the next type that must be used is the 16-bit short. As such, any prime numbers that rely on short rather than byte are using 2x the amount of memory.
In Kotlin JVM ecosystem, the Byte
data type is a signed integer, meaning that it uses one of it's 8 bits as a sign flag. This reduces the maximum permutations of bits from 256 to 128. One of those permutations must always correspond to zero, so the maximum number that can be represented on Kotlin JVM is 255, or 127.
Currently, the BytePrimeCache
supports prime numbers from 2 to 127, as it does not use unsigned bytes or work with the sign flag in any way.
Issue Statement
The BytePrimeCache
fails to make complete use of the byte data type. The memory required to represent prime numbers in the range 128 to 255, is 2x the theoretical limit. There are over 20 prime numbers in this range, almost as many prime numbers in the range 2 to 127.
Additional Affected Areas
ShortPrimeCache
relies on BytePrimeCache
for as many numbers as it can, as bytes are more efficient than shorts.
Guidance
Resolution Requirements