Demonstrates that Nucleo represents divide by zero result as inf, not an error.
Fork of ArrayLimits by
main.cpp
- Committer:
- CSTritt
- Date:
- 2017-10-12
- Revision:
- 2:68190b1e8bf3
- Parent:
- 1:a000e0121191
- Child:
- 3:f29617cd39a9
File content as of revision 2:68190b1e8bf3:
/* File: main.cpp Project: DivideByZero 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() { printf("Hello World !\n\n"); 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); } 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. }