| Thread overview | |||||
|---|---|---|---|---|---|
|
September 18, 2012 Variant opArithmetic | ||||
|---|---|---|---|---|
| ||||
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 Re: Variant opArithmetic | ||||
|---|---|---|---|---|
| ||||
Posted in reply to cal | 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 Re: Variant opArithmetic | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply