exp, infinity, isinf, fmin/fmax


Assume that:
double x = 10000.0;

and x is used in an expression which yields a result not finitely representable by the given floating-point type, such as:
double y = exp(x);


  1. Can I safely assume that under any valid OpenCL implementation (the code is designed for OpenCL 1.1) when y is not a finite number, it must be Inf (i.e., not NaN or something else), and hence the following expression always returns true (1):

  2. Moreover, assume my y is used in an expression as argument for say fmin, such as:
    double z = fmin(y * 20000.0 + 4.0, 55.0);
    Can I safely assume that if isinf(y) or isinf(y * 20000.0 + 4.0) holds, then z will always be properly initialized to 55.0?

Or is there some implementation-specific door open?


  1. This is true for desktop platforms. exp() should return HUGE_VALF, which evaluates to +infinity.

Embedded platforms do not necessarily handle infinity, in which case HUGE_VALF is the largest representable value.
You have to check CL_DEVICE_SINGLE_FP_CONFIG first.

  1. Yes. fmin() should return the finite value according to C99 specs.