Assume that we are working on a platform where the type long double
has a strictly greater precision than 64 bits. What is the fastest way to convert a given long double
to an ordinary double-precision number with some prescribed rounding (upward, downward, round-to-nearest, etc.)?
To make the question more precise, let me give a concrete example: Let N
be a given long double
, and M
be the double
whose value minimizes the (real) value M - N
such that M
> N
. This M
would be the upward rounded conversion I want to find.
Can I get away with setting the rounding mode of the FP environment appropriately and performing a simple cast (e.g. (double) N
)?
Clarification: You can assume that the platform supports the IEEE Standard for Floating-Point Arithmetic (IEEE 754).