Why does C++ mandate that complex only be instantiated for float, double, or long double?

前端 未结 2 1537
北恋
北恋 2020-12-15 15:49

According to the C++ ISO spec, §26.2/2:

The effect of instantiating the template complex for any type other than float,

2条回答
  •  旧时难觅i
    2020-12-15 16:16

    Probably for compatibility with the helper functions. For example:

    template T abs (const complex& x);
    

    If T == int, abs would return int, which would mean a massive loss in precision.

提交回复
热议问题