IEEE-754 Floating Point

The IEEE 754 standard determines the standard and structure of floating point numbers used by many and almost all modern systems. This standard has experienced an update in 2008 and is often called IEEE 754-2008 since then. But this little documentation is also dedicated to various systems released before 2008. It might be hard to understand how they work in detail so many examples used by various games of various systems will be given.

These are the most common floating point value types and their corresponding definitions. If you are interested in game hacking you may like to mind the representation of 1.0 in hexadecimal:

Name Total
Length
Pre 2008
Compatible
Usage Systems Exponent
Size
Mantissa
Size
Representation
of 1.0 in hexadecimal
Mini Float 8 Bits UNK Teaching UNK 4 Bits 3 Bits 38
Mini Float / Half Precision 16 Bits Yes Teaching, Graphics x64, x86, ARM 5 Bits 10 Bits 3C00
Single Precision 32 Bits Yes Most commonly used (Speed, Size, Audio Volume, Audio pitch, coordinates, colors and transparency, ...) x64, x86, PowerPC, ARM, N64, GCN, Wii, Wii U, Switch, 3DS, PS2, PS3, PS4, PS Vita, XBOX, XBOX 360, XBOX ONE, ... 8 Bits 23 Bits 3F800000
Double Precision 64 Bits Yes Commonly used (Physics, ...) x64, x86, PowerPC, ARM, GCN, Wii, Wii U, Switch, 3DS, PS2, PS3, PS4, PS Vita, XBOX, XBOX 360, XBOX ONE, ... 11 Bits 52 Bits 3FF0000000000000
Double Extended Precision 80 Bits No Less common x64, x86, ... 15 Bits 64 Bits 3FF0000000000000000
Quadruple Precision 128 Bits No Less common UNK 15 Bits 112 Bits 3FFF0000000000000000000000000000
Octuple Precision 256 Bits No Less common UNK 19 Bits 237 Bits 3FFFF000000000000000000000000000
00000000000000000000000000000000


    Converting a decimal fracture into floating point

How does an arbitrary decimal fracture turn into such a strange hex number? First of all you should keep in mind that floats are separated into 3 parts. The sign to express whether the float is positive or negative. It always only occupies one but the first bit. Is the first bit 0 we are looking at a positive float. 1 makes it negative. The second part determines the exponent (also called bias). The third part, the fraction (mantissa). Look at the table above to learn which lengths the exponent and fraction of each kind of floats have. Below you can find a sketch of a 32-bits floating point number:

Sign
(1 Bit)
Exponent
(8 Bits)
Mantissa
(23 Bits)
•••••••• •••••••••••••••••••••••


The first bit determines the sign. 0 = positive; 1 = negative.
The next 8 bits determine the exponent.
The left over 23 bits make the Mantissa, the value behind the dot.

Here's a simple example about how to convert the decimal fracture of 17.75 into IEEE floating point. A float to hex converter has output the following result: 0x418E0000. Let's do the same manually:

First you should determine the sign. As we can see there is no minus in front of our number. So it must be a positive number and our sign bit will be 0.
Next step is converting the value on the left side of the dot into binaries: 17 → 10001b. Now we have to calculate the fraction by multiplying the value of the right side of the dot by 2. Mind that the dot has to be carried. If the multiplication is equal or greater than 1 note a 1. If it's smaller than 1, note a 0. This procedure has to be done until the result is 0, infinitely repeats or you've have got 23 results:
0.75 * 2 = 1.5   1
0.5  * 2 = 1.0   1
0.0  * 2 = 0    0

└> 110

Use the result as mantissa:

Sign
(1 Bit)
Exponent
(8 Bits)
Mantissa
(23 Bits)
0 00010001 11000000000000000000000

But we are not finished now. The exponent field has yet to be correctly aligned. Imagine a dot between the Exponent and Mantissa field:
00010001.11000000000000000000000.Now move the dot to the left until it reaches the first 1 of the exponent field and count how many digits it was moved: 0001.00011100000000000000000 the dot was moved by 4 digits. The exponent becomes as high as many digits the dot was moved. The base of our exponential term is always 2 because if we now multiply our number by 2⁴ we will get the previous one back (00010001.110...). We now have to add the amount of times a digit was skipped to 127. 127 + 4 = 131. We now convert this back into binaries and use it as our new exponent value. (127 is being used because it's the biggest value where the first bit of the exponent field stays 0. If it'd be anything higher, 255 for instance the addition would cause an overflow). 131 → 10000011. We can now complete our floating point value:

Sign
(1 Bit)
Exponent
(8 Bits)
Mantissa
(23 Bits)
0 10000011 00011100000000000000000


Converting this binary number into hexadecimal leads you to 0x418E0000, the exact same number the float-to-hex converter has provided.


    Converting an IEEE Floating Point number into decima fracture

This procedure can be reversed. This will be shown with the following example: 0x42080000
First convert the float into binaries:

Sign
(1 Bit)
Exponent
(8 Bits)
Mantissa
(23 Bits)
0 10000100 00010000000000000000000


We can see that the sign is 0. So our number will be positive. Now convert the exponent field into decimal and subtract 127 from it.
10000100 → 132. 132 – 127 = 5
So we now have to put 1 into our exponent field followed by a dot and put the mantissa right behind it: 1.0001
This number has now to be multiplied by 2^5. First multiply the part on the left side of the dot by 2^5: 1 * 2⁵ = 32.
And now the part on the right side of the dot. Simply move the dot 5 digits to the right and add it to 32: 10.0000 = 2. 32 + 2 = 34.0
This is our converted float.


    Meaning of Floating Point Numbers to Video Game Hacking

Floats have a very important meaning when it comes to game hacking. The table on the top features a lot of examples. So every time you are using or creating cheats such as like as Moon Jumps, Speed Modifiers or Size Modifiers you are actually dealing with floats.


    Examples of Floating Point Numbers

    Velocity/Speed

The simpliest example of a floating point number might be the velocity of any object. Imagine you are driving a vehicle in a game which can accelerate, deccelerate and go backwards. When you are standing still the value will be 0x00000000 (0.0). The first frame you are accelerating the float will grow to a small value like 0.001 (0x3A83126F). The next frame 0.018 (0x3C9374BC) and so on. Later on the velocity could be anything higher. A float of 0x41C00000 (24.0) or anything higher is a very common value for the top speed of a vehicle.
If you go backwards the floating point number will have a negative sign. 0x41C00000 (24.0) would become 0xC1C00000 (-24.0).

Imagine your character is anywhere in any level. The character's position is definied by 3 floating point values. One float for each axis. All 3 axis mingle together at the zero-point. The value of every coordinate is 0x00000000 (0.0). The coordinate of the zero-point can be represented by 0.0; 0.0; 0.0. If you give your character these coordinate it will land on the exact center of the level (or where ever the creator of the level has placed the zero-point. But it's usually in the center). Going northbound (away from the zero-point) will usually make the float growing into the positive direction. Same for westbound and up into the sky. Going southbound (away from the zero-point) will make the float growing into the negative are.
Cheat codes like the Stalking Hack for Mario Kart Wii, Mario Kart 8 and Splatoon do nothing more than replacing your coordinate values with one opponent's ones.

    Time

Many 3D Zelda games and Pikmin games use a very clever method to simuate day times. The time is simply defined by a float growing from 0.0 to 360.0 (0x43B40000). 0.0 represents 00:00 am and 360.0 11.59 pm. By modifying this float you can jump on any time of the day. You can even make the day passing within a few seconds by changing it's assembly code which is very fun to see. Using a negative value can lead to odd effects here. In Zelda - The Wind Waker a negative time value will cause all colors to freak out. Even worse is the fact that this time value can be saved to the save file lol.

    3D Models

Even 3D models are nothing more than a bunch of floats. Just thousands of them! Each corner of a polygon has its own 3 floats to determine the position. And each polygon contains additional floats to determine the texture mapping. Keep in mind that larger models often have 5000+ polygons! And imagine the sum of polygons that gathers while being in a level...

    F-Curves

F-curves align the smoothness of animations. Most 3D games have one or more f-curves stored in memory. Such an f-curve is a string of thausands increasing and decreasing floats. Modyfing only a few of them can cause all animated things to spaz out.
Below you can find screenshots of such an f-curve found in Zelda - The Wind Waker:

String of increasing floats


Increment until 1.0, then decrement


Decrement until -0.000000087, then increment into negative area