fpuexcept.c 500 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <u.h>
  2. #include <libc.h>
  3. // Test that the FPU exceptions are working
  4. void
  5. pass(void) {
  6. print("PASS\n");
  7. exits("PASS");
  8. }
  9. void
  10. fail(const char *msg) {
  11. print("FAIL - %s\n", msg);
  12. exits("FAIL");
  13. }
  14. static float f = 10.0;
  15. int
  16. handlenote(void *ureg, char *note)
  17. {
  18. if (strstr(note, "Divide-By-Zero")) {
  19. pass();
  20. }
  21. fail("exception raised, but not divide by zero");
  22. return 1;
  23. }
  24. void
  25. main(void)
  26. {
  27. atnotify(handlenote, 1);
  28. f = f / 0.0f;
  29. fail("divide by zero exception not raised");
  30. }