digitalmars.D.learn - Variant opArithmetic
- cal (11/11) Sep 18 2012 Variant tries to mimic D's built-in rules for arithmetic
- Andrei Alexandrescu (8/18) Sep 18 2012 I wrote this:
- cal (3/25) Sep 18 2012 Sure thing
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?
Sep 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
Sep 18 2012
On Tuesday, 18 September 2012 at 19:02:33 UTC, Andrei Alexandrescu wrote:On 9/18/12 1:36 PM, cal wrote:Sure thingVariant 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
Sep 18 2012