Congratulations, now you know it works for 1 of the 4 Billion+ combinations of 32 bits.
"Proof by Working Example" is not a rigorous proof technique by any stretch of the imagination.
If a ATtiny is used as a I2C Slave to send information, then perhaps it is possible to send the integer value of analogRead() and do the math on the Master.
In many situations it is possible to do the math with integers.
Below is my test with the float16 library:
// Testing float16 library
// https://github.com/RobTillaart/float16
// For: https://forum.arduino.cc/t/a-2-byte-float/1170014
// This Wokwi project: https://wokwi.com/projects/376313228108456961
#include <TinyDebug.h> // a feature of Wokwi, an internal serial output
#include <float16.h>
void setup()
{
Debug.begin();
Debug.println("Test sketch for float16");
int iterations = 20;
Debug.println(PiGregoryLeibniz16(iterations));
Debug.println(PiGregoryLeibniz32(iterations),10);
}
void loop() {}
// The Gregory-Leibniz method
float16 PiGregoryLeibniz16(int n)
{
float16 pi(1);
const float16 one(1);
const float16 two(2);
unsigned int count = 3;
for(int i=0; i<n; i++)
{
pi -= one / float16(count);
count += 2;
pi += one / float16(count);
count += 2;
}
return(float16(4)*pi);
}
// The Gregory-Leibniz method
float PiGregoryLeibniz32(int n)
{
float pi = 1.0;
unsigned int count = 3;
for(int i=0; i<n; i++)
{
pi -= 1.0 / (float) count;
count += 2.0;
pi += 1.0 / (float) count;
count += 2.0;
}
return(4.0 * pi);
}
What's that exponent worth in decimal? It allows for numbers roughly between E-4 to E+4.
For more significant digits or higher exponents I've developed a floating exponent format, with up to 13 bits significand and 8 bits exponent as opposed to only 11 and 5 bits of 16 bit IEEE 754 numbers.
The maximum representable value is (2−2^−10) × 2^15 = 65504.
So what?
FP16 is used extensively in neural networks and computer graphics in applications where speed is much more important than accuracy. Multiplication and division are an order of magnitude or more faster than with 32 or 64 bit floats.
They represent a reasonable number of useful fractions as well as whole numbers.
Really "whole" numbers extend to 2047 with 11 bits. All numbers above that can not be incremented by 1 because the difference between adjacent numbers (precision) becomes 2 or more.
To obtain the real value (0.333325195) from the binary16 value (0x3555), can I use the following template/formula? If yes, then what will be the value for m? (It was 127 for binary32 format.)