# Float32AVR
Original Russian version is located in [dev](https://github.com/igor-240340/Float32AVR/tree/dev) branch.

## Overview

This library provides floating-point routines with single precision for AVR microcontrollers. It has been built entirely from the ground up, with all floating-point algorithms developed based on fundamental binary arithmetic principles.

The main goal of this library is not for production use but rather for educational purposes, allowing users to understand and experiment with floating-point arithmetic. This library can be easily ported to any microcontroller.

It is used in the "Hardware Calculator From Scratch" project, which can be found in [this](https://github.com/igor-240340/HardwareCalculatorFromScratch) repository.

## IEEE 754 Compliance

- Only one rounding mode: to nearest/ties to even.
- No subnormals: if underflows, it flushes to zero.
- No special values: inf, nan.
- Only positive zero.

## Research and Proofs

There is a tutorial that explains all the theory behind "Hardware Calculator From Scratch" project in the whole which you can find in the corresponding repo specified above.

A formal proof for the division algorithm with an immovable divisor can be found [here](docs/Деление%20двоичных%20целых%20чисел.odt) (the tutorial contains less rigorous but more intuitive explanation).

## Testing

An auxiliary repository with test examples is available [here](https://github.com/igor-240340/Float32AVRTest). Each test example in this library has a desktop equivalent in that repository. The primary goal is to ensure that our floating-point library produces the same results as hardware floating-point operations in a desktop environment (excluding behaviors for subnormals and inf/nan, which we do not support).

## Features

- **FADD32/FSUB32**: Addition/subtraction.
- **FMUL32**: Multiplication.
- **FDIV32**: Division.
- **FTOAN**: Converts float to ASCII string (supports only normalized decimal numbers, uses a simple algorithm that does not generally provide the best approximation).
- **FTOAE**: Converts float to ASCII string in exponential format (it depends on FTOAN).
- **ATOF**: Converts ASCII string to float (uses a simple algorithm that does not generally provide the best approximation).
- **FTOI**: Converts from float to int (intended for internal use by the library only, currently limited to integers with a size of 1 byte).
- **ITOF**: Converts from int to float (intended for internal use by the library only, currently limited to integers with a size of 1 byte).

## Flowcharts
### FADD32
![](docs/flowchart_fadd_en.png)
### FMUL32
![](docs/flowchart_fmul_en.png)
### FDIV32
![](docs/flowchart_fdiv_en.png)
### FTOAN
![](docs/flowchart_ftoan_en.png)
### FTOAE
![](docs/flowchart_ftoae_en.png)
### ATOF
![](docs/flowchart_atof_en.png)
