So why double to float conversion is implicit ?
Basile B.
b2.temp at gmx.com
Sun Oct 22 12:19:08 UTC 2017
On Sunday, 22 October 2017 at 12:17:49 UTC, Basile B. wrote:
> On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote:
>> [...]
>
> Fortunately D provides enough to simplify self-discipline:
>
> ---
> import std.traits;
>
> struct FP(T)
> if (isFloatingPoint!T)
> {
> T _value;
> alias _value this;
>
> void antiCoercion(V)()
> {
> static assert(V.sizeof <= T.sizeof, "C++ float coercion
> is not allowed");
> }
>
> this(V)(V v) {antiCoercion!V; _value = v;}
> void opAssign(V)(V v) {antiCoercion!V; _value = v;}
> }
>
> void main()
> {
> import std.math;
> FP!single PiOver2 = (atan(1.0) * 4) / 2;
> }
> ---
Oh, I meant to write "FP!float PiOver2 = (atan(1.0) * 4) / 2;"
More information about the Digitalmars-d
mailing list