2

A friend of mine was using the function std::polar believing that it takes only one argument, which corresponds to the argument (how confusing!) of the returned complex number. As you know, this is not true, since the function takes two argument, viz., the modulus and the argument. What puzzles me is the fact that the second argument is optional and defaults to zero. When you omit the second argument, all it does is to convert a real number to a complex. When is this useful and why has it been added to the specification (or is it really a part of the spec)? After all, hadn't the second argument been optional, he wouldn't have wasted plenty of time to spot the bug.

Pteromys
  • 1,441
  • 2
  • 12
  • 29
  • 2
    It is really part of the spec. I can't comment on why the library designers thought it would be a good idea. – Mike Seymour May 10 '13 at 11:09
  • @MikeSeymour Could you please tell me how to check something is a part of the spec in general? – Pteromys May 10 '13 at 11:13
  • See this :http://stackoverflow.com/questions/81656/where-do-i-find-the-current-c-or-c-standard-documents – BЈовић May 10 '13 at 11:15
  • 1
    @Pteromys: I do that by reading the spec. If you don't want to pay for the [official document](http://webstore.ansi.org/RecordDetail.aspx?sku=INCITS%2fISO%2fIEC+14882-2012), then a draft is available [here](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf). – Mike Seymour May 10 '13 at 11:26
  • Maybe to parallel `std::complex`'s (i.e. the constructors) behaviour? Although then the first argument should also default to `0`... – filmor May 10 '13 at 13:50

0 Answers0