An open API service indexing awesome lists of open source software.

https://github.com/igor-240340/float32avr

Floating-Point Routines for AVR MCUs
https://github.com/igor-240340/float32avr

assembly-language atmega avr binary-arithmetic floating-point ieee-754

Last synced: 2 months ago
JSON representation

Floating-Point Routines for AVR MCUs

Awesome Lists containing this project

README

        

# 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

Some of the research notes can be found [here](https://drive.google.com/open?id=17ViZAw4rgcqFg06v3ZrvuvWtl1nly2Ic&usp=drive_fs).

A formal proof for the division algorithm with an immovable divisor can be found [here](https://drive.google.com/open?id=10WZpMqTUmbDx7oKYT3m1wm0OJeUH0PQj&usp=drive_fs). (I couldn't find a good one, so I had to write it myself.)

## 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)