Click here to Skip to main content
15,885,914 members
Articles / Programming Languages / C++

Building a simple C++ script compiler from Scintilla and CINT

Rate me:
Please Sign up or sign in to vote.
4.73/5 (25 votes)
8 Jul 2006CPOL7 min read 153.9K   7.6K   85  
How to build a simple C++ script compiler from Scintilla and CINT.
/**************************************************************************
* Complex.C
*
*
**************************************************************************/

#include "Complex.h"

void Complex::disp(void)
{
  printf("(%g,%g)",re,im);
}


Complex operator +(Complex const & a,Complex const & b)
{
	Complex c;
	c.re = a.re+b.re;
	c.im = a.im+b.im;
	return(c);
}

Complex operator -(Complex const & a,Complex const & b)
{
	Complex c;
	c.re = a.re-b.re;
	c.im = a.im-b.im;
	return(c);
}

Complex operator *(Complex const & a,Complex const & b)
{
	Complex c;
	c.re = a.re*b.re-a.im*b.im;
	c.im = a.re*b.im+a.im*b.re;
	return(c);
}

Complex operator /(Complex const & a,Complex const & b)
{
	Complex c;
	double x;
	x = b.re*b.re+b.im*b.im;
	c.re = (a.re*b.re+a.im*b.im)/x;
	c.im = (a.im*b.re-a.re*b.im)/x;
	return(c);
}

//**********************************************************************

Complex exp(Complex& a)
{
	Complex c;
	double mag;
	mag = exp(a.re);
	c.re=mag*cos(a.im);
	c.im=mag*sin(a.im);
	return(c);
}

double fabs(Complex& a)
{
	double result;
	result = sqrt(a.re*a.re+a.im*a.im);
	return(result);
}

double real(Complex& a)
{
	return(a.re);
}

double imag(Complex& a)
{
	return(a.im);
}



//**********************************************************************
ostream& operator<<(ostream& ios,Complex& a)
{
  ios << '(' << a.real() << ',' << a.imag() << ')' ;
  ios.flush();
  return(ios);
}



// Added for test
const int cf1(const int a){return(a);}
const int& cf2(const int& a){return(a);}
int const& cf3(int const& a){return(a);}
int const & cf4(int const & a){return(a);}
int const & cf5(int const & a){return(a);}
const int & cf6(const int & a){return(a);}
const int* cf7(const int* a){return(a);}
const int *const cf8(const int *const a){return(a);}
const int * const cf9(const int * const a){return(a);}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions