LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-09-2016, 05:12 PM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Rep: Reputation: Disabled
Some quirky C++ statements.


Hi there. My environment is Linux Ubuntu 14.04. I am trying to adjust a C++ Gauss-Legendre Quadrature (one of hundreds of implementations) to my project. The code can be had at this link:

http://www.holoborodko.com/pavel/num...l-integration/

There are a couple of variants there, to get the code I use, one has to click on this link (download):

Gauss-Legendre Quadrature.zip in the section Gauss-Legendre Quadrature for C/C++

I tried to include one of the files: gauss_legendre.c into my project file and it did not compile with a bunch of compilation errors. I look at some statements there and hardly understand how they work.

(1) Statement on line 455:

Code:
x0 = cos(PI*(double)((i<<2)-1)*t1)*t0;
The error:

invalid type argument of unary * (have double)

Is this statement a bitwise shift to the left?

(2) I also need to understand this code (lines 63-65):

Code:
#ifndef FABS
  #define FABS(a) ((a)>=0?(a):-(a))
#endif
I will appreciate any comment.

Thanks, - Alex

Last edited by AlexBB; 01-09-2016 at 08:37 PM.
 
Old 01-10-2016, 03:35 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Hi Alex
Quote:
Is this statement a bitwise shift to the left?
Yes. In effect multiplying i by 2^2.

Code:
#ifndef FABS   // if FABS is not defined, define it.
  #define FABS(a) ((a)>=0?(a):-(a))     
#endif
Everywhere the preprocessor finds FABS(a) it will substitute ((a)>=0?(a):-(a))
?: is the conditional operator. FABS(a) determines the absolute value of a.

To illustrate, run the preprocessor (gcc -E fabs.c) on the following:
Code:
#ifndef FABS
	#define FABS(a) ((a)>=0?(a):-(a))
#endif

int main()
{
    FABS(-2);
}
I assume the author uses that code, to avoid function calls to pow() and abs(), in the interest of processing speed.

Regarding the error, you haven't supplied enough information. Can you show us how you are implementing the code?

Last edited by norobro; 01-10-2016 at 06:47 PM. Reason: missing # in code
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Quirky 7.0.1 Screencast jeremy Linux - Screencasts and Screenshots 0 03-12-2015 07:44 AM
Quirky CPU? Super TWiT Linux - Hardware 17 05-04-2011 08:35 AM
Quirky key behavior darenw Linux - Software 4 11-26-2010 03:41 PM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM
X Crash *quirky this one is* DaFrEQ Linux - General 5 10-31-2002 02:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration