Project

General

Profile

Actions

Feature #15066

closed

Documentation and providing better API for accessing Complex numbers functions in C extensions

Added by v0dro (Sameer Deshmukh) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:88827]

Description

Currently there is absolutely no documentation for working with Complex numbers at the level of the C API.

Apart from two macros defined [here] for setting the real and imag
values of Complex numbers there is no 'official' way of working with Complex numbers at the level of the C API.

I propose two things:

  • Fully document existing Complex number routines.
  • Provide a robust and efficient API for dealing with complex numbers from C extensions.

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

RCOMPLEX_SET_REAL and RCOMPLEX_SET_IMAG are internal macros, and so I think they should not be used outside.

Updated by Eregon (Benoit Daloze) over 5 years ago

Isn't it enough to just use rb_funcall() to call Ruby methods on Complex numbers?

Updated by v0dro (Sameer Deshmukh) over 5 years ago

Isn't it enough to just use rb_funcall() to call Ruby methods on Complex numbers?

Calling Ruby methods in C extensions defeats the purpose of writing a C extension since a non-trivial number of Ruby method calls take up significant time.

RCOMPLEX_SET_REAL and RCOMPLEX_SET_IMAG are internal macros, and so I think they should not be used outside.

Both these macros are included in the ruby.h so I thought they're public. Maybe you want to remove them from there?

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Open to Feedback

v0dro (Sameer Deshmukh) wrote:

Isn't it enough to just use rb_funcall() to call Ruby methods on Complex numbers?

Calling Ruby methods in C extensions defeats the purpose of writing a C extension since a non-trivial number of Ruby method calls take up significant time.

What APIs do you need?
A concrete list, please.

RCOMPLEX_SET_REAL and RCOMPLEX_SET_IMAG are internal macros, and so I think they should not be used outside.

Both these macros are included in the ruby.h so I thought they're public. Maybe you want to remove them from there?

Removed them yesterday.

Updated by Eregon (Benoit Daloze) over 5 years ago

v0dro (Sameer Deshmukh) wrote:

Isn't it enough to just use rb_funcall() to call Ruby methods on Complex numbers?

Calling Ruby methods in C extensions defeats the purpose of writing a C extension since a non-trivial number of Ruby method calls take up significant time.

The existing Ruby methods should already be fast enough for most cases.
C macros/functions for accessing the real and the imaginary parts seems fine, but I think not more than that should be exposed for Complex.

Updated by v0dro (Sameer Deshmukh) over 5 years ago

Isn't it enough to just use rb_funcall() to call Ruby methods on Complex numbers?

Calling Ruby methods in C extensions defeats the purpose of writing a C extension since a non-trivial number of Ruby method calls take up significant time.

What APIs do you need?
A concrete list, please.

As Benoit says (rightly), I don't think we need a very elaborate API. Therefore the following functions would be sufficient:

  • Constructor from double: Something like rb_complex_new(double real, double imag).
  • Access real and imag parts: Something like rb_complex_get_real(VALUE complex_number) and rb_complex_get_imag(VALUE complex_number).
  • Basic operations: complement, addition, subtraction, multiplication and division.

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

At the meeting today, mrkn also wanted these APIs.

Actions #9

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Feedback to Closed

Applied in changeset trunk|r66360.


complex.c: new APIs for Complex

[Feature #15066]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0