0.1.7 float16

This commit is contained in:
rob tillaart 2022-11-07 14:26:49 +01:00
parent 6e182d283d
commit 45d082fadb
8 changed files with 75 additions and 37 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,4 +23,8 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico
libraries:
- "printHelpers"

View File

@ -0,0 +1,42 @@
# Change Log Float16
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.7] - 2022-11-07
- add changelog.md
- add rp2040 to build-CI
- update readme.md
- update keywords.txt
## [0.1.6] - 2021-12-18
- update library.json
- update license
- minor edits
## [0.1.5] - 2021-12-02
- add basic math
- optimize compare operators
## [0.1.4] - 2021-11-26
- setup repo to get it working again.
- still experimental.
----
## [0.1.03] - eons ago ??
- ??
## [0.1.02] - 2015-03-14
- getting rounding right
## [0.1.01] - 2015-03-12
- make base conversion separate functions
## [0.1.00] - 2015-03-10
- initial version

View File

@ -1,19 +1,11 @@
//
// FILE: float16.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.5
// VERSION: 0.1.7
// PURPOSE: library for Float16s for Arduino
// URL: http://en.wikipedia.org/wiki/Half-precision_floating-point_format
//
// HISTORY:
// 0.1.00 2015-03-10 initial version
// 0.1.01 2015-03-12 make base conversion separate functions
// 0.1.02 2015-03-14 getting rounding right
// 0.1.03
// 0.1.4 2021-11-26 setup repo to get it working again.
// still experimental.
// 0.1.5 2021-12-02 add basic math, optimize compare operators
// 0.1.6 2021-12-18 update library.json, license, minor edits
// HISTORY: see changelog.md
#include "float16.h"
@ -27,7 +19,6 @@ float16::float16(double f)
_value = f32tof16(f);
}
// PRINTING
size_t float16::printTo(Print& p) const
{
@ -35,7 +26,6 @@ size_t float16::printTo(Print& p) const
return p.print(d, _decimals);
};
double float16::toDouble() const
{
return f16tof32(_value);
@ -51,7 +41,6 @@ bool float16::operator == (const float16 &f)
return (_value == f._value);
}
bool float16::operator != (const float16 &f)
{
return (_value != f._value);
@ -111,46 +100,39 @@ float16 float16::operator + (const float16 &f)
return float16(this->toDouble() + f.toDouble());
}
float16 float16::operator - (const float16 &f)
{
return float16(this->toDouble() - f.toDouble());
}
float16 float16::operator * (const float16 &f)
{
return float16(this->toDouble() * f.toDouble());
}
float16 float16::operator / (const float16 &f)
{
return float16(this->toDouble() / f.toDouble());
}
float16& float16::operator += (const float16 &f)
{
*this = this->toDouble() + f.toDouble();
return *this;
}
float16& float16::operator -= (const float16 &f)
{
*this = this->toDouble() - f.toDouble();
return *this;
}
float16& float16::operator *= (const float16 &f)
{
*this = this->toDouble() * f.toDouble();
return *this;
}
float16& float16::operator /= (const float16 &f)
{
*this = this->toDouble() / f.toDouble();
@ -170,7 +152,6 @@ int float16::sign()
return 0;
}
bool float16::isZero()
{
return ((_value & 0x7FFF) == 0x0000);
@ -231,7 +212,6 @@ float float16::f16tof32(uint16_t _value) const
return sgn ? -f : f;
}
uint16_t float16::f32tof16(float f) const
{
uint32_t t = *(uint32_t *) &f;

View File

@ -2,7 +2,7 @@
//
// FILE: float16.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.6
// VERSION: 0.1.7
// PURPOSE: Arduino library to implement float16 data type.
// half-precision floating point format,
// used for efficient storage and transport.
@ -12,7 +12,7 @@
#include "Arduino.h"
#define FLOAT16_LIB_VERSION (F("0.1.6"))
#define FLOAT16_LIB_VERSION (F("0.1.7"))
class float16: public Printable

View File

@ -6,7 +6,14 @@ float16 KEYWORD1
# Methods and Functions (KEYWORD2)
toDouble KEYWORD2
getBinary KEYWORD2
setBinary KEYWORD2
setDecimals KEYWORD2
getDecimals KEYWORD2
# Constants (LITERAL1)
FLOAT16_LIB_VERSION LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/float16.git"
},
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=float16
version=0.1.6
version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to implement float16 data type.

View File

@ -88,8 +88,6 @@ unittest(test_constructor)
unittest(test_compare_equal)
{
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
float16 a(1);
float16 b(1);
float16 c(2);
@ -110,8 +108,6 @@ unittest(test_compare_equal)
unittest(test_compare_1nequal)
{
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
float16 a(1);
float16 b(1);
float16 c(2);
@ -138,8 +134,6 @@ unittest(test_compare_1nequal)
unittest(test_negation)
{
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
float16 f16(123.456);
float16 f17(-f16);
float16 f18 = -f16;
@ -151,8 +145,6 @@ unittest(test_negation)
unittest(test_conversion)
{
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
for (int i = 0; i < 20; i++)
{
float f = random(60000000) * 0.001;
@ -164,8 +156,6 @@ unittest(test_conversion)
unittest(test_printable)
{
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
float16 f16(123.456);
// test default value.
assertEqual(4, f16.getDecimals());