Thread overview
Variant opArithmetic
Sep 18, 2012
cal
Sep 18, 2012
cal
September 18, 2012
Variant tries to mimic D's built-in rules for arithmetic conversions but:

import std.variant, std.stdio;
void main()
{
  auto v1 = Variant(4.5f);
  auto v2 = Variant(3.5f);
  writeln((v1+v2).type()); // double
}

The reason is Variant doesn't try to convert to float in opArithmetic (it's is easily fixed). But is it intentional?
September 18, 2012
On 9/18/12 1:36 PM, cal wrote:
> Variant tries to mimic D's built-in rules for arithmetic conversions but:
>
> import std.variant, std.stdio;
> void main()
> {
> auto v1 = Variant(4.5f);
> auto v2 = Variant(3.5f);
> writeln((v1+v2).type()); // double
> }
>
> The reason is Variant doesn't try to convert to float in opArithmetic
> (it's is easily fixed). But is it intentional?

I wrote this:

    writeln(typeof(4.5f + 3.5f).stringof);

To my surprise, the reported type was float, not double. Well that means it's a bug in Variant, could you please make a bug report (and hopefully a pull request fixing it)?


Thanks,

Andrei
September 18, 2012
On Tuesday, 18 September 2012 at 19:02:33 UTC, Andrei Alexandrescu wrote:
> On 9/18/12 1:36 PM, cal wrote:
>> Variant tries to mimic D's built-in rules for arithmetic conversions but:
>>
>> import std.variant, std.stdio;
>> void main()
>> {
>> auto v1 = Variant(4.5f);
>> auto v2 = Variant(3.5f);
>> writeln((v1+v2).type()); // double
>> }
>>
>> The reason is Variant doesn't try to convert to float in opArithmetic
>> (it's is easily fixed). But is it intentional?
>
> I wrote this:
>
>     writeln(typeof(4.5f + 3.5f).stringof);
>
> To my surprise, the reported type was float, not double. Well that means it's a bug in Variant, could you please make a bug report (and hopefully a pull request fixing it)?
>
>
> Thanks,
>
> Andrei

Sure thing