How to convert double to 'long double' as standard

How to convert doubleto long doubleas a C ++ standard. I think this is simply not the case?

double value = 1.2;
long double newValue = (long double)value;
+4
source share
3 answers

This will work fine, but will not magically create extra precision newValue. That is, this will not lead to the same result as:

long double newValue = 1.2L;

which will set newValuecloser to 1.2.

+4
source

Standards ensure that it long doublecan support all the values ​​that a can have double(or, in other words, the set of values ​​supported by a doubleis a subset of what a long doublecan represent).

,

long double newValue = value;

, value double long double, . , .

++

long double newValue = (long double)value;    // as in original question
long double newvalue = static_cast<long double>(value);

, , .

, ( long double double), , ( ) - ( ) .

+4

static_cast:

long double newValue = static_cast<long double>(value);

++ 11:

auto newValue = static_cast<long double>(value);

(known as "explicitly entered initialization identifier").

+2
source

All Articles