Demonstrates that Nucleo represents divide by zero result as inf, not an error.
Fork of ArrayLimits by
Diff: main.cpp
- Revision:
- 2:68190b1e8bf3
- Parent:
- 1:a000e0121191
- Child:
- 3:f29617cd39a9
--- a/main.cpp Thu Oct 12 19:57:14 2017 +0000 +++ b/main.cpp Thu Oct 12 20:40:08 2017 +0000 @@ -1,35 +1,27 @@ /* File: main.cpp - Project: ArrayLimits + Project: DivideByZero -//------------------------------------ -// Tera Term configurations -// Terminal - New-line, Receive LF, Transmit LF -// Serial port - Data 8 bit, Parity none, Stop 1 bit data, Flow control none. -// Baud as specified below. -//------------------------------------ - -// Serial pc(SERIAL_TX, SERIAL_RX, 921600); // Highest Tera Term speed - works. -// Serial pc(USBTX, USBRX, 115200); // Highest common speed - works. -// Serial pc(USBTX, USBRX); // Default 9600 baud, alternate pin names - works. + Demonstrates divide by zero on Nucleo boards. Result is inf, not an error. + + Created by Dr. C. S. Tritt; Last revised 10/12/17 (v. 1.0) */ #include "mbed.h" int main() { - float a[] {1.0, 3.0, 5.0, 7.0, 9.0 }; - printf("Hello World !\n"); + printf("Hello World !\n\n"); - for (int i = 0; i > -10; i--) { // Displays zeros and one NaN. - printf("a[%d] is %f.\n", i, a[i]); + for (int i = 5; i >= -5; i--) { // Displays inf for 1/0. + float x = (float) i; + printf("x is %f and 1/x is %f.\n", x, 1/x); wait(0.5f); } - for (int i = 0; i < 10; i++) { // Hangs after 6th value! - printf("a[%d] is %f.\n", i, a[i]); - wait(0.5f); - } + float x = 1.0f/0.0f; // Produces compile time warning. + // Prints three infs. + printf("\nx, x+1.0 & 2.0*x are: %f, %f, %f.\n", x, x+1.0f, 2.0f*x); while (true) {}; // Just loop here forever after tests. } \ No newline at end of file