22// FILE: float16_test_all.ino
33// AUTHOR: Rob Tillaart
44// PURPOSE: test float16
5- // DATE: 2021-11-27
65// URL: https://github.com/RobTillaart/float16
7- //
8-
9- // test all values except the NAN
10- // test_1 takes ~ 2 minutes on UNO @ 115200baud
116
12- // https://github.com/RobTillaart/float16/issues/2
7+ // test all values except the NAN
8+ // test_1 takes ~ 2 minutes on UNO @ 115200baud
9+ // https://github.com/RobTillaart/float16/issues/2
10+ //
11+ // test_3 is related to issue #10
1312
1413
1514#include " float16.h"
@@ -34,6 +33,7 @@ void setup()
3433
3534 test_1 ();
3635 test_2 ();
36+ test_3 ();
3737}
3838
3939
@@ -42,8 +42,41 @@ void loop()
4242}
4343
4444
45+ // test for issue #10
46+ void test_3 ()
47+ {
48+ Serial.println (__FUNCTION__);
49+ uint16_t y = 0 ;
50+ uint16_t last = 0 ;
51+
52+ start = millis ();
53+ for (int32_t x = 1 ; x < 65535 ; x++) // test positive integers.
54+ // for (int32_t x = -1; x > -65535; x--) // test negative integers.
55+ {
56+ last = y;
57+ f16 = x;
58+ y = f16 .getBinary ();
59+ if (y < last)
60+ {
61+ Serial.print (" | " );
62+ Serial.print (x);
63+ Serial.print (" | " );
64+ Serial.print (y, HEX);
65+ Serial.print (" | " );
66+ Serial.print (last, HEX);
67+ Serial.println (" |" );
68+ }
69+ }
70+ stop = millis ();
71+ Serial.println ();
72+ Serial.print (" TIME: " );
73+ Serial.println (stop - start);
74+ }
75+
76+
4577void test_2 ()
4678{
79+ Serial.println (__FUNCTION__);
4780 start = millis ();
4881 for (uint32_t x = 0x0001 ; x < 0x7C01 ; x++)
4982 {
@@ -64,7 +97,8 @@ void test_2()
6497
6598void test_1 ()
6699{
67- // POSITIVE NUMBERS
100+ Serial.println (__FUNCTION__);
101+ // POSITIVE NUMBERS
68102 prev = 0 ;
69103 errors = 0 ;
70104 start = millis ();
@@ -76,7 +110,7 @@ void test_1()
76110 Serial.print (' \t ' );
77111 float current = f16 .toDouble ();
78112 Serial.print (current, 8 );
79- if (prev > current) // numbers should be increasing.
113+ if (prev > current) // numbers should be increasing.
80114 {
81115 Serial.print (" \t\t ERROR" );
82116 errors++;
@@ -94,7 +128,7 @@ void test_1()
94128 Serial.println ();
95129
96130
97- // NEGATIVE NUMBERS
131+ // NEGATIVE NUMBERS
98132 prev = 0 ;
99133 errors = 0 ;
100134 start = millis ();
@@ -106,7 +140,7 @@ void test_1()
106140 Serial.print (' \t ' );
107141 float current = f16 .toDouble ();
108142 Serial.print (current, 8 );
109- if (prev < current) // negative numbers should be decreasing.
143+ if (prev < current) // negative numbers should be decreasing.
110144 {
111145 Serial.print (" \t\t ERROR" );
112146 errors++;
@@ -129,4 +163,4 @@ void test_1()
129163
130164
131165
132- // -- END OF FILE --
166+ // -- END OF FILE --
0 commit comments