/******************************************************************************/ /* */ /* FILE: june.cpp */ /* */ /* I finally found an application for the C++ complex */ /* ================================================== */ /* */ /* Compiled and tested with Visual C++ V6.0 */ /* */ /* V1.00 30-JUN-2002 P. Tellenbach https://www.heimetli.ch/ */ /* */ /******************************************************************************/ #include <iostream> #include <complex> #include <algorithm> using namespace std ; #define CONSTANT complex<double>(0,0.448798950512827605494663340468) complex<double> table[] = { complex<double>( 581.2500, 0.0000), complex<double>(-164.0940, -125.6900), complex<double>( 18.7120, -242.6540), complex<double>( -22.7807, -25.1399), complex<double>( 72.1255, 32.4917), complex<double>( -27.1256, -113.7790), complex<double>( -29.8375, 17.3722), complex<double>( 77.5000, 1.383845e-014) } ; class Function { protected: double value ; int index ; double loop ; public: Function( int l ) : value(0.0), index(0), loop(l) { } void operator()( const complex<double> &cplx ) { value += real( cplx * exp( CONSTANT * loop * (double)index++) ) ; } friend ostream &operator<<( ostream &os, Function &func ) { os << (char)(func.value / 7) ; return os ; } } ; int main( ) { for( int k = 0; k < 14; k++ ) cout << for_each( table, table + 8, Function(k) ) ; return 0 ; }
Update 30. June 2022
The compiler produced an impressive error message with 265 lines! This was fixed by adding a single const...
/******************************************************************************/ /* */ /* FILE: june.cpp */ /* */ /* I finally found an application for the C++ complex */ /* ================================================== */ /* */ /* Compiled and tested with Visual C++ V6.0 */ /* */ /* V1.00 30-JUN-2002 P. Tellenbach https://www.heimetli.ch/ */ /* */ /* Compiled and tested with g++ 10.2.1 */ /* */ /* V1.10 30-JUN-2022 P. Tellenbach https://www.heimetli.ch/ */ /* */ /******************************************************************************/ #include <iostream> #include <complex> #include <algorithm> using namespace std ; #define CONSTANT complex<double>(0,0.448798950512827605494663340468) complex<double> table[] = { complex<double>( 581.2500, 0.0000), complex<double>(-164.0940, -125.6900), complex<double>( 18.7120, -242.6540), complex<double>( -22.7807, -25.1399), complex<double>( 72.1255, 32.4917), complex<double>( -27.1256, -113.7790), complex<double>( -29.8375, 17.3722), complex<double>( 77.5000, 1.383845e-014) } ; class Function { protected: double value ; int index ; double loop ; public: Function( int l ) : value(0.0), index(0), loop(l) { } void operator()( const complex<double> &cplx ) { value += real( cplx * exp( CONSTANT * loop * (double)index++) ) ; } friend ostream &operator<<( ostream &os, const Function &func ) { os << (char)(func.value / 7) ; return os ; } } ; int main( ) { for( int k = 0; k < 14; k++ ) cout << for_each( table, table + 8, Function(k) ) ; return 0 ; }