Tier 1 Series 3

3B: Floats vs. Ints

Pilot Record
Student Profile
"You don't measure a pilot's altitude in whole miles if you're landing, and you don't count the number of passengers using decimals. If your AI uses an Integer for smooth movement, the ship will jitter. If it uses a Float to count inventory items, you'll end up with 0.99999 of a laser pistol. A skilled Engineer audits for Numerical Intent."

The Concept: Precision vs. Wholeness

In C#, choosing the right "container" for your data prevents rounding errors that can crash your flight systems.

int (Integer): For whole numbers. Counting ammunition, kills, or mission checkpoints.
float (Floating Point): For decimal precision. Speed, distance, time, and health.
Red Flag Detected

The AI Trap: "The Jittery Rounder"

You ask the AI: "Slowly move the ship toward the hangar."

// AI-Generated Code: Jittery and Low-Precision
public int moveSpeed = 5; 

void Update() {
    // Audit Fail: If the move increment is less than 1, 
    // an integer will round it to zero. The ship won't move at all!
    transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}

This is "Rounding Deadlock." Because Time.deltaTime is a tiny decimal (like 0.016), multiplying it by an integer often results in a value so small that the integer rounds it back to 0. The ship stays docked while the engine is running.

Elite Telemetry

Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."

  • Small Batches Solving one problem at a time prevents logic drift.
  • Modular Design Localizing the "blast radius" of AI changes.
  • Tight Loops Rapid iteration with constant code review.

The Mechanic's Correction

Corrective Protocol
// Corrected: Using a float (f suffix) for smooth calculus
[SerializeField] private float moveSpeed = 5.5f;

void Update() {
    // The decimal precision allows for buttery smooth flight
    transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
Your Pilot Command
> Use ScriptableObjects to decouple data from logic and save memory.
Next Mission
The String Menace