GY-63_MS5611/libraries/Fraction/readme.md

52 lines
1.9 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/Fraction/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-11-01 10:56:22 -04:00
[![Arduino-lint](https://github.com/RobTillaart/Fraction/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Fraction/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/Fraction/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Fraction/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Fraction/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Fraction.svg?maxAge=3600)](https://github.com/RobTillaart/Fraction/releases)
2021-11-01 10:56:22 -04:00
2020-11-27 05:16:22 -05:00
# Fraction
2021-11-01 10:56:22 -04:00
Arduino library to implement a Fraction data type (experimental)
2020-11-27 05:16:22 -05:00
## Description
The fraction library implements fractional numbers a.k.a. Q,
(integers are Z and floats/doubles are R),
and the conversion to floats.
2015-03-01 08:19:14 -05:00
The code is working with a number of limitations among others:
- denominator is max 4 digits to keep code for multiply and divide simple
2020-11-27 05:16:22 -05:00
- Fractions are not exact (even floats are not exact)
2015-03-01 08:19:14 -05:00
- the range of numbers supported is limited.
2020-11-27 05:16:22 -05:00
- code is experimental still.
2015-03-01 08:19:14 -05:00
That said, the library is useful e.g. to display float numbers as a fraction.
2021-11-01 10:56:22 -04:00
From programming point of view the **fractionize()** function, converting a double
2015-03-01 08:19:14 -05:00
into a fraction is a nice programming problem, fast with a minimal error.
2020-11-27 05:16:22 -05:00
In short, use fractions with care otherwise your sketch might get broken ;)
2021-11-01 10:56:22 -04:00
2020-11-27 05:16:22 -05:00
## Operations
See examples
2021-11-01 10:56:22 -04:00
2020-11-27 05:16:22 -05:00
## Use with care
The library is reasonably tested, and if problems arise please let me know.
2021-11-01 10:56:22 -04:00
## Future
- experiment with bigger nominator/denominator using all of 32767 possibilities ?
- investigate divide by zero errors
- investigate better fractionize() - depends on nom/denom size
- test test test ...
- add famous constants as Fraction e.g FRAC_PI = (355, 113) ??
-