1

I'm trying to create a program that receives an expression with floating point numbers and shows if any exceptions occurred.

I know that if I wrote it in C, it would be like this:

#include <stdio.h>
#include <fenv.h>

//floating point math happens before calling the function
void displayExceptions() {
    printf("Exception FE_DIVBYZERO: %d\n", fetestexcept(FE_DIVBYZERO));
    printf("Exception FE_INEXACT: %d\n", fetestexcept(FE_INEXACT));
    printf("Exception FE_INVALID: %d\n", fetestexcept(FE_INVALID));
    printf("Exception FE_OVERFLOW: %d\n", fetestexcept(FE_OVERFLOW));
    printf("Exception FE_UNDERFLOW: %d\n", fetestexcept(FE_UNDERFLOW));
}

Is there a way to check those exceptions in go?

mello_
  • 11
  • 1

1 Answers1

0

AFAIK, no; however many of them will produce NaN, Inf or 0.0, which can be tested for using math.IsNaN(x), math.IsInf(x) and x == 0.0.

Amadan
  • 191,408
  • 23
  • 240
  • 301