On Saturday, 13 January 2018 at 17:19:31 UTC, kdevel wrote:

How can I convert a decimalX to float/double/real?

Implicit conversion is not available at library level, D does not have an implicit conversion operator;

Subtracting decimalX - real will result in a decimalX. This was a design decision, but I'm open to suggestions.

The following code works:

    real r;
    for (r = 1; r < 6; r += .1L) {
        decimal128 d = r;
        auto dsin = sin (d);
        auto rsin = sin (r);
        auto delta = dsin - rsin; //delta is decimal128
writefln ("%9.2f %30.24f %30.24f %12.4g", r, rsin, dsin, delta);
    }

if you really need to convert decimalX values to floating point counterparts, you'll need to cast them:

x = cast(real)somedecimalvalue;

(but update your files before this, I discovered a bug in opCast)




Reply via email to