Feature #1316

Phasor.rb: Complex number class using polar coordinates

Added by Peter Hillerström almost 8 years ago. Updated about 5 years ago.

Target version:



I am writing a sound synthesis program, and I needed a way to easily generate and manipulate complex sound samples (analytic signal), so I wrote a new class by adapting the Ruby Complex Number class by Keiju ISHITSUKA to make calculations using polar coordinates.

I know the complex number class in 1.9 is written in C, but I hope this would inspire someone to make a C version using polar coordinates too... Anyway, do what you wish with this. As I mainly needed to multiply and add phasors with scalars, some methods may have bugs or inaccuracies with complex arguments. There are still some weirdness in substraction (2 tests fail), and most of the trigonometry functions are absent.

I tried to use svn diff to make a patch file out of the class, but that didn't work as expected - diff didn't see my file at all, but instead tried to diff against several other files, so I will just attach the file and unit tests here.

Peter H.

phasor.rb View - Phasor.rb: Complex number class using polar coordinates (10.4 KB) Peter Hillerström, 03/26/2009 04:58 PM

test_phasor.rb View (7.61 KB) Peter Hillerström, 03/26/2009 04:58 PM


#1 Updated by Marc-Andre Lafortune over 7 years ago

  • Priority changed from Normal to 3
  • Assignee set to Yukihiro Matsumoto



#2 Updated by Yusuke Endoh almost 7 years ago

  • Target version set to 2.0.0



#3 Updated by Shyouhei Urabe over 6 years ago

  • Status changed from Open to Assigned



#4 [ruby-core:36964] Updated by Koichi Sasada over 5 years ago

  • Assignee changed from Yukihiro Matsumoto to Kenta Murata

mrkn, what do you think about it?

#5 [ruby-core:42548] Updated by Yusuke Endoh about 5 years ago

Hello mrkn,

Bumping this. Please let us know your opinion.

IMHO, it is not Ruby way to define another class that has the same set
of methods and different representation. That's like defining a "List"
class for "Array."

But part of me also is purely interested in the feature.

Yusuke Endoh

#6 [ruby-core:42559] Updated by Kenta Murata about 5 years ago

  • Status changed from Assigned to Rejected

I think these features are provided as a gem.

Also available in: Atom PDF