0
0
Embedded Cprogramming~3 mins

Why Floating point cost on embedded systems in Embedded C? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if a tiny change in your math could make your device last hours longer on battery?

The Scenario

Imagine you are programming a small device like a fitness tracker or a thermostat. You need to do math with decimal numbers, like calculating temperature or speed. You try to do this using floating point numbers manually, but the device is slow and the battery drains quickly.

The Problem

Using floating point math on tiny devices without special hardware is very slow and uses a lot of energy. The processor has to do many extra steps to handle decimals, which makes your program lag and wastes battery life. This makes your device less reliable and frustrating to use.

The Solution

Understanding the cost of floating point operations helps you write smarter code. You can choose to avoid floating point math when possible or use fixed-point math instead. This makes your program faster and saves battery, making your device work better and longer.

Before vs After
Before
float result = a / b; // floating point division on embedded CPU
After
int result = (a * 1000) / b; // fixed-point math to avoid float
What It Enables

Knowing floating point costs lets you optimize embedded programs for speed and battery life, making devices more efficient and user-friendly.

Real Life Example

A smartwatch calculating heart rate without floating point math can run longer on a single charge and respond faster to your movements.

Key Takeaways

Floating point math is slow and power-hungry on small devices.

Avoiding or minimizing floating point operations improves speed and battery life.

Using fixed-point math or careful design makes embedded systems work better.