Skip to content

A High School-Level recreation of Java's BigInteger Class.

Notifications You must be signed in to change notification settings

notKeion/SmallInteger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

SmallInteger

EARLY DEVELOPMENT STAGE, NOT STABLE

A High School-Level recreation of Java's BigInteger Class. With this, the hope was to create a more memory efficient solution as BigInteger stores each digit as an int veriable inside of an array. This array was dynamicly resized corespondent to how many digits were stored.

With SmallInteger however, this utilizes a dynamicly resized byte array to store each digit, not only storing 1 byte per digit stored apose to the 4 bytes stored per digit (BigInteger), but this also dramaticly decreases the time needed to calculate as less data needs to be shifted, copied, etc.

Features:

  • Reduced space complexity
  • Precise digit by digit calculations
  • Automatic digit carrying to reduce useless place values when shrinking array
  • Fully functional add, subtract and multiply algorithms (division is to be implemented stably in next iteration)
  • Reduced temporary variables to decrease peak memory usage during runtime

Public Methods:

  • .length() returns number of digits.
  • .toByteArray() returns number digit by digit as byte array, most sigificant digit in place at the front.
  • .compareTo() returns -1,0,1 if compared number is smaller, equal or larger.
  • .toInteger() returns number as Integer if number does not exceed INTEGER.MAXIMUM
  • .carry() iterates linearly over array and starts from last index, carries numbers >10 to coresponding neighbour, this is done after adding or during runtime with multiplication.

Math Methods: These methods are initiated by a call to the method and a switch will switch between different experimental algorithms (will be simplified in later releases)

  • .add()
  • .subtract()
  • .multiply()

Screenshot from 2022-06-10 07-20-31

About

A High School-Level recreation of Java's BigInteger Class.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages