开发者

iPhone -- working with complex numbers

I'm trying to figure out the best way to put complex numbers into my math-oriented iPhone app. I've found the mac osx manual page for complex numbers, which looks like a reasonable start. Three questions:

(1) Is this the best starting point?

(2) I will need an object-oriented wrapper -- can NSValue do this somehow? Or should I just write my own? (not difficult, but I'd rather use a built-in one if it exists).

(3) Is there a built-in way to get a 开发者_如何学Cstring representation of a complex?


  1. Seems reasonable.
  2. I would just create a class of your own which has a complex ivar. It might be possible to subclass NSNumber (and thus NSValue) to do something sane, but you'll have to be a bit careful.
  3. No, just get the real and imaginary parts and print those.


As far as I know, there's no built-in complex number support in Cocoa (other than the C libraries). It sounds like you have a good approach. I haven't looked at it carefully yet, but here's a cocoa calculator with source code that supports complex numbers--you might be able to get some ideas.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜