mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.7 float16
This commit is contained in:
parent
6e182d283d
commit
45d082fadb
@ -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:
|
compile:
|
||||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
platforms:
|
platforms:
|
||||||
@ -9,3 +24,7 @@ compile:
|
|||||||
- esp32
|
- esp32
|
||||||
# - esp8266
|
# - esp8266
|
||||||
# - mega2560
|
# - mega2560
|
||||||
|
- rpipico
|
||||||
|
|
||||||
|
libraries:
|
||||||
|
- "printHelpers"
|
||||||
|
42
libraries/float16/CHANGELOG.md
Normal file
42
libraries/float16/CHANGELOG.md
Normal 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
|
||||||
|
|
@ -1,19 +1,11 @@
|
|||||||
//
|
//
|
||||||
// FILE: float16.cpp
|
// FILE: float16.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.5
|
// VERSION: 0.1.7
|
||||||
// PURPOSE: library for Float16s for Arduino
|
// PURPOSE: library for Float16s for Arduino
|
||||||
// URL: http://en.wikipedia.org/wiki/Half-precision_floating-point_format
|
// URL: http://en.wikipedia.org/wiki/Half-precision_floating-point_format
|
||||||
//
|
//
|
||||||
// HISTORY:
|
// HISTORY: see changelog.md
|
||||||
// 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
|
|
||||||
|
|
||||||
|
|
||||||
#include "float16.h"
|
#include "float16.h"
|
||||||
@ -27,7 +19,6 @@ float16::float16(double f)
|
|||||||
_value = f32tof16(f);
|
_value = f32tof16(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PRINTING
|
// PRINTING
|
||||||
size_t float16::printTo(Print& p) const
|
size_t float16::printTo(Print& p) const
|
||||||
{
|
{
|
||||||
@ -35,7 +26,6 @@ size_t float16::printTo(Print& p) const
|
|||||||
return p.print(d, _decimals);
|
return p.print(d, _decimals);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
double float16::toDouble() const
|
double float16::toDouble() const
|
||||||
{
|
{
|
||||||
return f16tof32(_value);
|
return f16tof32(_value);
|
||||||
@ -51,7 +41,6 @@ bool float16::operator == (const float16 &f)
|
|||||||
return (_value == f._value);
|
return (_value == f._value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool float16::operator != (const float16 &f)
|
bool float16::operator != (const float16 &f)
|
||||||
{
|
{
|
||||||
return (_value != f._value);
|
return (_value != f._value);
|
||||||
@ -111,46 +100,39 @@ float16 float16::operator + (const float16 &f)
|
|||||||
return float16(this->toDouble() + f.toDouble());
|
return float16(this->toDouble() + f.toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16 float16::operator - (const float16 &f)
|
float16 float16::operator - (const float16 &f)
|
||||||
{
|
{
|
||||||
return float16(this->toDouble() - f.toDouble());
|
return float16(this->toDouble() - f.toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16 float16::operator * (const float16 &f)
|
float16 float16::operator * (const float16 &f)
|
||||||
{
|
{
|
||||||
return float16(this->toDouble() * f.toDouble());
|
return float16(this->toDouble() * f.toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16 float16::operator / (const float16 &f)
|
float16 float16::operator / (const float16 &f)
|
||||||
{
|
{
|
||||||
return float16(this->toDouble() / f.toDouble());
|
return float16(this->toDouble() / f.toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16& float16::operator += (const float16 &f)
|
float16& float16::operator += (const float16 &f)
|
||||||
{
|
{
|
||||||
*this = this->toDouble() + f.toDouble();
|
*this = this->toDouble() + f.toDouble();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16& float16::operator -= (const float16 &f)
|
float16& float16::operator -= (const float16 &f)
|
||||||
{
|
{
|
||||||
*this = this->toDouble() - f.toDouble();
|
*this = this->toDouble() - f.toDouble();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16& float16::operator *= (const float16 &f)
|
float16& float16::operator *= (const float16 &f)
|
||||||
{
|
{
|
||||||
*this = this->toDouble() * f.toDouble();
|
*this = this->toDouble() * f.toDouble();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float16& float16::operator /= (const float16 &f)
|
float16& float16::operator /= (const float16 &f)
|
||||||
{
|
{
|
||||||
*this = this->toDouble() / f.toDouble();
|
*this = this->toDouble() / f.toDouble();
|
||||||
@ -170,7 +152,6 @@ int float16::sign()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool float16::isZero()
|
bool float16::isZero()
|
||||||
{
|
{
|
||||||
return ((_value & 0x7FFF) == 0x0000);
|
return ((_value & 0x7FFF) == 0x0000);
|
||||||
@ -231,7 +212,6 @@ float float16::f16tof32(uint16_t _value) const
|
|||||||
return sgn ? -f : f;
|
return sgn ? -f : f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t float16::f32tof16(float f) const
|
uint16_t float16::f32tof16(float f) const
|
||||||
{
|
{
|
||||||
uint32_t t = *(uint32_t *) &f;
|
uint32_t t = *(uint32_t *) &f;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: float16.h
|
// FILE: float16.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.6
|
// VERSION: 0.1.7
|
||||||
// PURPOSE: Arduino library to implement float16 data type.
|
// PURPOSE: Arduino library to implement float16 data type.
|
||||||
// half-precision floating point format,
|
// half-precision floating point format,
|
||||||
// used for efficient storage and transport.
|
// used for efficient storage and transport.
|
||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define FLOAT16_LIB_VERSION (F("0.1.6"))
|
#define FLOAT16_LIB_VERSION (F("0.1.7"))
|
||||||
|
|
||||||
|
|
||||||
class float16: public Printable
|
class float16: public Printable
|
||||||
|
@ -6,7 +6,14 @@ float16 KEYWORD1
|
|||||||
|
|
||||||
|
|
||||||
# Methods and Functions (KEYWORD2)
|
# Methods and Functions (KEYWORD2)
|
||||||
|
toDouble KEYWORD2
|
||||||
|
getBinary KEYWORD2
|
||||||
|
setBinary KEYWORD2
|
||||||
|
|
||||||
|
setDecimals KEYWORD2
|
||||||
|
getDecimals KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
|
FLOAT16_LIB_VERSION LITERAL1
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/float16.git"
|
"url": "https://github.com/RobTillaart/float16.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.6",
|
"version": "0.1.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=float16
|
name=float16
|
||||||
version=0.1.6
|
version=0.1.7
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino library to implement float16 data type.
|
sentence=Arduino library to implement float16 data type.
|
||||||
|
@ -88,8 +88,6 @@ unittest(test_constructor)
|
|||||||
|
|
||||||
unittest(test_compare_equal)
|
unittest(test_compare_equal)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
|
|
||||||
|
|
||||||
float16 a(1);
|
float16 a(1);
|
||||||
float16 b(1);
|
float16 b(1);
|
||||||
float16 c(2);
|
float16 c(2);
|
||||||
@ -110,8 +108,6 @@ unittest(test_compare_equal)
|
|||||||
|
|
||||||
unittest(test_compare_1nequal)
|
unittest(test_compare_1nequal)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
|
|
||||||
|
|
||||||
float16 a(1);
|
float16 a(1);
|
||||||
float16 b(1);
|
float16 b(1);
|
||||||
float16 c(2);
|
float16 c(2);
|
||||||
@ -138,8 +134,6 @@ unittest(test_compare_1nequal)
|
|||||||
|
|
||||||
unittest(test_negation)
|
unittest(test_negation)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
|
|
||||||
|
|
||||||
float16 f16(123.456);
|
float16 f16(123.456);
|
||||||
float16 f17(-f16);
|
float16 f17(-f16);
|
||||||
float16 f18 = -f16;
|
float16 f18 = -f16;
|
||||||
@ -151,8 +145,6 @@ unittest(test_negation)
|
|||||||
|
|
||||||
unittest(test_conversion)
|
unittest(test_conversion)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
|
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
float f = random(60000000) * 0.001;
|
float f = random(60000000) * 0.001;
|
||||||
@ -164,8 +156,6 @@ unittest(test_conversion)
|
|||||||
|
|
||||||
unittest(test_printable)
|
unittest(test_printable)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FLOAT16_LIB_VERSION: %s\n", (char*) FLOAT16_LIB_VERSION);
|
|
||||||
|
|
||||||
float16 f16(123.456);
|
float16 f16(123.456);
|
||||||
// test default value.
|
// test default value.
|
||||||
assertEqual(4, f16.getDecimals());
|
assertEqual(4, f16.getDecimals());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user