File: compile3.cpp

package info (click to toggle)
ginac 1.5.8-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,628 kB
  • ctags: 4,936
  • sloc: cpp: 44,703; sh: 11,126; perl: 1,157; yacc: 763; makefile: 414; lex: 200; sed: 32
file content (36 lines) | stat: -rw-r--r-- 971 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <ctime>
#include <iostream>
using namespace std;
#include <ginac/ginac.h>
using namespace GiNaC;

/*
 * Demonstrates the use of link_ex.
 *
 * When run for the first time link_ex will fail. This is a rude way of
 * checking whether the needed .so file is available.  The .so is then created
 * by compile_ex using the filename parameter. When run again link_ex will use
 * the existing .so file.
 *
 */
int main()
{
	FUNCP_2P fp;
	try {
		link_ex("compile3_testprg.so", fp);
		cout << "Using existing 'compile3_testprg.so'." << endl;
	}
	catch (const std::exception& e) {
		// hope the exception is just raised because of missing 'compile2_testprg.so' file,
		// so being lazy no error management here ...
		cout << "Error: " << e.what() << endl;
		cout << "Building new 'compile3_testprg.so'." << endl;
		symbol a, b;
		ex expr = a*b;
		compile_ex(expr, a, b, fp, "compile3_testprg");
	}

	cout << "result of 2.3*1.5 is " << fp(2.3, 1.5) << endl;

	return 0;
}