c++ - How to prevent overflow when using usual math functions exp() log()? -


all in title. how check possible overflow when using 2 functions exp() , log()?

to expand answer of @theotherguy, can cancel operation if overflow occurs.

#include <stdio.h> #include <math.h> #include <errno.h>  int main(void) {     double param, result;      errno = 0;     param = 1e3;     result = exp (param);     if (errno == erange) {         printf("exp(%f) overflows\n", param);         result = param;     }     printf ("the exponential value of %f %f.\n", param, result );     return 0; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -