0.1.13 Fraction

This commit is contained in:
rob tillaart 2021-12-18 14:10:11 +01:00
parent cf87923609
commit 9c5c9df875
12 changed files with 20 additions and 22 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2015-2021 Rob Tillaart
Copyright (c) 2015-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,6 @@
//
// FILE: FractionFindSum.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// PURPOSE: demo
// DATE: 13-feb-2015
// URL: https://github.com/RobTillaart/Fraction

View File

@ -1,11 +1,9 @@
//
// FILE: FractionMediant.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Find fraction by binary search with mediant.
// DATE: 2020-04-21
//
// this method is not that fast but it shows a nice application for
// the mediant.

View File

@ -1,7 +1,6 @@
//
// FILE: fractionExerciser.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// PURPOSE: demo sketch for fraction math
// DATE: 2015-03-29
// URL: https://github.com/RobTillaart/Fraction

View File

@ -1,11 +1,9 @@
//
// FILE: fractionTest01.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// PURPOSE: test sketch for fraction math
// DATE: 2015-01-25
// URL: https://github.com/RobTillaart/Fraction
//
#include "fraction.h"

View File

@ -1,13 +1,14 @@
//
// FILE: fraction.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.12
// VERSION: 0.1.13
// PURPOSE: Arduino library to implement a Fraction datatype
// URL: https://github.com/RobTillaart/Fraction
//
//
// HISTORY
// 0.1.12 2021-11-01 update Arduino-CI, badges,
// 0.1.13 2021-12-18 update library.json, license, minot edits
// 0.1.12 2021-11-01 update Arduino-CI, badges,
// refactor
// 0.1.11 2020-12-23 arduino-CI + unit tests
// 0.1.10 2020-06-10 fix library.json
@ -68,13 +69,13 @@ void Fraction::split(float f)
// Normalize to 0.0 ... 1.0
bool negative = f < 0;
if (negative) f = -f;
// TODO investigate different strategy:
// intpart = int32_t(f); // strip of the integer part.
// f = f - intpart; // determine remainder
// determine n, d
// n += intpart * d; // add integer part * denominator to fraction.
bool reciproke = f > 1;
if (reciproke) f = 1/f;
@ -206,7 +207,7 @@ Fraction Fraction::operator - (const Fraction &c)
Fraction Fraction::operator * (const Fraction &c)
{
return Fraction(n * c.n, d * c.d);
return Fraction(n * c.n, d * c.d);
}
@ -393,7 +394,7 @@ void Fraction::simplify()
// (100x) micros()=96048
// showed errors for very small values around 0
void Fraction::fractionize(float val)
{
{
// find nearest fraction
float Precision = 0.0000001;
Fraction low(0, 1); // "A" = 0/1

View File

@ -2,15 +2,15 @@
//
// FILE: fraction.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.12
// PURPOSE: Arduino library to implement a Fraction datatype
// VERSION: 0.1.13
// PURPOSE: Arduino library to implement a Fraction datatype
// URL: https://github.com/RobTillaart/Fraction
//
#include "Arduino.h"
#define FRACTION_LIB_VERSION (F("0.1.12"))
#define FRACTION_LIB_VERSION (F("0.1.13"))
class Fraction: public Printable

View File

@ -10,6 +10,7 @@ toDouble KEYWORD2
toFloat KEYWORD2
isProper KEYWORD2
toAngle KEYWORD2
nominator KEYWORD2
denominator KEYWORD2
mediant KEYWORD2

View File

@ -15,7 +15,8 @@
"type": "git",
"url": "https://github.com/RobTillaart/Fraction.git"
},
"version":"0.1.12",
"version": "0.1.13",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "fraction.h"
}

View File

@ -1,5 +1,5 @@
name=Fraction
version=0.1.12
version=0.1.13
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to implement a Fraction datatype

View File

@ -8,7 +8,7 @@
# Fraction
Arduino library to implement a Fraction data type (experimental)
Arduino library to implement a Fraction data type (experimental).
## Description
@ -42,6 +42,8 @@ The library is reasonably tested, and if problems arise please let me know.
## Future
- improve documentation
- extend unit tests
- experiment with bigger nominator/denominator using all of 32767 possibilities ?
- investigate divide by zero errors
- investigate better fractionize() - depends on nom/denom size

View File

@ -32,6 +32,7 @@
unittest_setup()
{
fprintf(stderr, "FRACTION_LIB_VERSION: %s\n", (char*) FRACTION_LIB_VERSION);
}
unittest_teardown()
@ -41,8 +42,6 @@ unittest_teardown()
unittest(test_constructor)
{
fprintf(stderr, "VERSION:\t%s\n", (char*) FRACTION_LIB_VERSION);
Fraction pi(PI);
assertEqual(355, pi.nominator());
assertEqual(113, pi.denominator());