Cave Story Big Integers, Floats, and Complex Numbers

Nov 22, 2012 at 4:04 PM
Not anymore
"Run, rabbit run. Dig that hole, forget the sun."
Join Date: Jan 28, 2010
Location: Internet
Posts: 1369
Age: 34
Consider Cave Story. Now consider floats, very large integers, and complex numbers.
  • Floats: floats are real numbers. In other words, they include all the numbers starting from negative infinity to positive infinity exclusive. They cover every rational number and every integer, and then some. Floats are numbers represented with a decimal point, such as 3.6, 5.12, 3.1415926..., or 18.0.
  • Large Integers: Whole numbers greater than 2 to the power of 32.
  • Complex Numbers: complex numbers are pairs of floats. They have one real and one imaginary part. Examples include 3.1 + 5.8i, 15.676 - 32.256777i, and 3.0 + 999.0i.
We can easily implement floats without writing any new assembly code. In fact, we do not have to use the x86 floating point instruction set.

How?

Consider your basic 32-bit integer. Or even a 16-bit integer.
Using integers, it is possible to construct a floating point number.

We only have to use Noxid's <VAR or TSC+ hack, which already exists.

Since the <VAR hack allows us to use integers in TSC and makes TSC much more Turing complete than it was before, it is easy to set up floats.

Floats are pairs of integers. Floats have a value and an exponent:

(1, -3) = 1 * 10 ^ -3 = 1e-3 = 0.001

Or how about...

(314159265, -8) = 314159265 * 10 ^ -8 = 3.14159265

We can also do:

(2, 100) = 2 * 10 ^ 100 = 2 * (a googol)

Notice that with our pair system, we can suddenly represent:
  • Any floating point number, to 9 or 10 decimal places (32-bit integers have a maximum of 10 decimal digits).
  • Very large numbers such as 2 * googol, as long as we don't care about the least significant decimal digits (the ones on the right side of the number).
Complex numbers are easy to implement using <VAR too. We just make them quadruples of integers instead of pairs of integers.
By adding in more integers, you can have arbitrary length integers (known in Java as BigIntegers) as well.

Once again, you can write all of this functionality in TSC as long as you have decent comparison operators as well as some form of if statement that can accept compares on integers.

(If you are wondering why regular floats only allow 7 digits of precision while our system offers 9 or 10, it is because regular floats are lame and use up a few bits for infinity, negative infinity, negative 0, and especially the whole slew of NaN (not a number). Plus we are going for two integers instead of just one 32-bit value. We have far more exponents to choose from.)
 
Nov 23, 2012 at 5:48 PM
The Preacher
"Wacka-Wacka-Wacka-Wacka-Wacka-Wacka-Wacka-Wacka-BLEIUP"
Join Date: Feb 20, 2011
Location: lost in translation
Posts: 336
Age: 31
I don't understand (314159265, -1) = 3.14159265
Shouldn't it be either (314159265, 0) or (314159265, -8), depending on whether XXX as the first integer is interpreted as X.XX or XXX.0 by default?
 
Nov 23, 2012 at 5:57 PM
Not anymore
"Run, rabbit run. Dig that hole, forget the sun."
Join Date: Jan 28, 2010
Location: Internet
Posts: 1369
Age: 34
Oh that's wrong. It should be (314159265, -8).
 
Top