samedi 20 août 2016

Type conversions without loss of precision

I've just recently noticed some of the code in the framework I am working with converts certain variables to doubles and then back when they are accessed by the framework. In the C++11 standard, is this guaranteed to work without loss of precision for any integral types? If so, which? Are there any additional types that are universally safe for this kind of conversion in common implementations?

Also, is there any way to check at compile time that a conversion is safe in this way? Essentially I would like something like:

static_assert(T(double(T type))==type);

Aucun commentaire:

Enregistrer un commentaire