Skip to content

complex_double_get function#1123

Merged
isuruf merged 1 commit intosymengine:masterfrom
ShikharJ:Issue1088F3
Nov 13, 2016
Merged

complex_double_get function#1123
isuruf merged 1 commit intosymengine:masterfrom
ShikharJ:Issue1088F3

Conversation

@ShikharJ
Copy link
Copy Markdown
Member

@ShikharJ ShikharJ commented Nov 13, 2016

Relevant: Issue #1088 Feature 3.
For the course of development refer: PR #1122.

@ShikharJ
Copy link
Copy Markdown
Member Author

@isuruf A review?

@isuruf
Copy link
Copy Markdown
Member

isuruf commented Nov 13, 2016

Can you fix the commit message? Otherwise +1 to merge

@ShikharJ
Copy link
Copy Markdown
Member Author

Done.

@isuruf isuruf merged commit 08b4bf6 into symengine:master Nov 13, 2016
@ShikharJ ShikharJ deleted the Issue1088F3 branch November 13, 2016 19:10
Copy link
Copy Markdown
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for coming to this PR so late. I think we should rather just use the native C complex type. Here is an example how to use it:

#include <stdio.h>
#include <complex.h>
#include <tgmath.h>
 
int main(void)
{
    double complex z1 = I * I;     // imaginary unit squared
    printf("I * I = %.1f%+.1fi\n", creal(z1), cimag(z1));
 
    double complex z2 = pow(I, 2); // imaginary unit squared
    printf("pow(I, 2) = %.1f%+.1fi\n", creal(z2), cimag(z2));
 
    double PI = acos(-1);
    double complex z3 = exp(I * PI); // Euler's formula
    printf("exp(I*PI) = %.1f%+.1fi\n", creal(z3), cimag(z3));
 
    double complex z4 = 1+2*I, z5 = 1-2*I; // conjugates
    printf("(1+2i)*(1-2i) = %.1f%+.1fi\n", creal(z4*z5), cimag(z4*z5));
}

typedef struct dcomplex {
double real;
double imag;
} dcomplex;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining our own complex type, why cannot we use the C complex type?

http://en.cppreference.com/w/c/numeric/complex

@ShikharJ
Copy link
Copy Markdown
Member Author

@certik This is exactly what was planned on implementing initially. Using double complex. The problem that arised was that using I from C99 gave an error like this
error: unable to find numeric literal operator ‘operator""iF’
d = i.imag()*_Complex_I + i.real();
( _Complex_I is a macro for I)
This is a well known error, and can still be resolved by using -fext-numeric-literals flag. But again, this flag only worked locally (as my system uses gcc 5.4.0, and Travis uses previous versions). The builds failed, and as per isuruf's suggestion, it would be easier to return a structure instead of using double complex. Hence this implementation.

@certik
Copy link
Copy Markdown
Contributor

certik commented Nov 23, 2016

@ShikharJ would you mind creating a new issue for this? Let's discuss it over there, there must be some solution to that.

@certik
Copy link
Copy Markdown
Contributor

certik commented Nov 23, 2016

I created an issue for it here: #1131

@isuruf isuruf mentioned this pull request Nov 26, 2016
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants